SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 add data to where clause
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

allan8964
Posting Yak Master

247 Posts

Posted - 06/06/2012 :  10:21:25  Show Profile  Reply with Quote
Hi there,

I need to grab some items into a where clause, see below:
table1
ID | Location
10| New York
11| Dallas
...

select * from table2 where Location = 'New York' or Location = 'Dallas' ...


How can I select Location from table1 to where clause in table2?
Thanks in advance.

webfred
Flowing Fount of Yak Knowledge

Germany
8764 Posts

Posted - 06/06/2012 :  10:23:47  Show Profile  Visit webfred's Homepage  Reply with Quote
select * from table2 where location in (select distinct location from table1)


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

nigelrivett
Flowing Fount of Yak Knowledge

United Kingdom
3383 Posts

Posted - 06/06/2012 :  10:23:48  Show Profile  Visit nigelrivett's Homepage  Reply with Quote
select * from table2 where Location in (select location frrom table)

or
select t2.*
from table2 t2
join table1 t1
on t1.location = t2.location

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

allan8964
Posting Yak Master

247 Posts

Posted - 06/06/2012 :  10:31:31  Show Profile  Reply with Quote
Thanks webfred and nigelrivett, I never thought it's this simple! Thanks again.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000