Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Query help - loop

Author  Topic 

Mondeo
Constraint Violating Yak Guru

287 Posts

Posted - 2014-06-03 : 05:07:54
If I have a simple table like this

id make model
1 ford mondeo
2 ford escort
3 vauxhall corsa
4 fiat punto

To get a list of id's I can do SELECT id FROM table WHERE make='ford' and model='mondeo'

But, I have a second table like this

make model
ford escort
ford mondeo
etc

I want to get all the id's from table 1 that match all the make/model combinations in table 2.

How could I do that?

Thanks

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2014-06-03 : 05:22:13
select t1.id
from table1 as t1
join table2 as t2 on t1.make=t2.make and t1.model=t2.model


Too old to Rock'n'Roll too young to die.
Go to Top of Page
   

- Advertisement -