SQL advanced sub select query

sql

I would like to expand on this simple sub select:

Select * from table1 where pkid in (select fkid from table2 where clause...)

The logic above is fairly simple – get me all rows in table1 where the pkid is contained in the subset returned from the sub select query that has a where clause. It works well because there is only 1 field being returned.

Now I want to expand on this.

In table 1 I want to return results where field1 and field2 and field3 in select (field1, field2, field3 from table2 where clause…)

How is this possible?

Thanks in advance.

Example.

TABLE1

FIELD1  FIELD2 FIELD3    
1       2      3    
2       3      4     
4       5      6

TABLE 2

2       3      4 
4       5      6

I want to return 2 results.

Best Answer

If I understand what you need you can try:

SELECT t1.field1, t1.field2, t1.field3 FROM table1 t1
INNER JOIN table2 t2
    ON t1.field1 = t2.field1
   AND t1.field2 = t2.field2
   AND t1.field3 = t2.field3
   AND t2.... // Use this as WHERE condition