INNER JOIN的类型查询(SELECT DISTINCT)?

时间:2017-06-05 10:24:01

标签: servicestack ormlite-servicestack

是否可以创建一个生成以下SQL的类型化查询?

SELECT A.*
FROM schema1.Table1 A
INNER JOIN (SELECT DISTINCT column1, column2 FROM schema1.Table2) B ON A.column1 = B.column1

1 个答案:

答案 0 :(得分:1)

您无法使用类型化的API加入子选择,实现此功能的最简单方法是使用CustomJoin,例如:

var table1 = db.GetTableName<Table1>();
var q = db.From<Table1>()
    .CustomJoin($@"INNER JOIN 
        (SELECT DISTINCT column1, column2 FROM schema1.Table2) B 
        ON {table1}.column1 = B.column1");