Christer Carlsund
Christer Carlsund

Reputation: 1281

Typed query for INNER JOIN (SELECT DISTINCT)?

Is it possible to create a typed query that produces the following SQL?

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

Upvotes: 2

Views: 128

Answers (1)

mythz
mythz

Reputation: 143349

You can't join a sub select with a typed API, the easiest way to implement this would be to use a CustomJoin, e.g:

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");

Upvotes: 1

Related Questions