Using Inner Join in FilterClause

103 views Asked by At

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?

1

There are 1 answers

4
Gordon Linoff On BEST ANSWER

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
                        )