简体   繁体   中英

Using Inner Join in FilterClause

I am rewriting the synchronization in a old project, and I want to keep it as similar to the old code as possible.

The old code had SQL codes that are similar to the FilterClause . And until now it has been very simple to convert the old codes select expressions to the corresponding FilterClause. For instance:

SELECT * FROM dbo.table_a WHERE num_id = @id

has been translated to:

...FilterClause = "num_id = @id";

However, now I have run into a problem...

The FilterClauses definition is Gets or sets the SQL WHERE clause (without the WHERE keyword) that is used to filter the result set from the base table. But now my sql expression is:

SELECT * 
FROM dbo.table_a
INNER JOIN 
(
 SELECT DISTINCT(num_id) 
 FROM dbo.link_table_ab
 WHERE link_table_ab.b_index = 5
) T2 ON table_a.num_id= T2.num_id

So the problem is that there is no WHERE in the primary query... What do I do?

You can implement essentially the same logic using IN with a subquery in the WHERE clause. Does this work for you?

SELECT * 
FROM dbo.table_a
WHERE table_a.num_id IN (SELECT num_id
                         FROM dbo.link_table_ab
                         WHERE link_table_ab.b_index = 5
                        )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM