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.
| Author |
Topic |
|
hamid.y
Starting Member
22 Posts |
Posted - 2010-03-01 : 06:13:04
|
| I wanna select all records which is equal with a set of IDs.Table1:ID | Name | city-----------------1 jack new york2 john Ohio3 jenny LATable2:ID-----12desirable result:-----------------every records in Table1 which its ID is Equal with Table2 IDor this problem----------------select * from Table1where ID = (select ID from Table2)but pay attention (select ID from Table2) return more than one record.and i want to select all Records of Table1 where its IDs is equal with all each ID returned by second select. |
|
|
senthil_nagore
Master Smack Fu Yak Hacker
1007 Posts |
Posted - 2010-03-01 : 06:15:37
|
| select * from Table1where ID in (select ID from Table2)Senthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceledhttp://senthilnagore.blogspot.com/ |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2010-03-01 : 06:22:11
|
| try this tooselect t.* from table1 t join table2 t2 on t.id = t2.idselect * from table1 t where exists (select * from table2 where id = t.id |
 |
|
|
hamid.y
Starting Member
22 Posts |
Posted - 2010-03-01 : 06:23:50
|
| no no.i want adopt something like for statement in interface programming.i want select records of table1 where is equal with one by one records of table2.thats it |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-03-01 : 10:46:17
|
quote: Originally posted by hamid.y no no.i want adopt something like for statement in interface programming.i want select records of table1 where is equal with one by one records of table2.thats it
thats exactly what query suggested does.did you try it?if yes, why do you still think its not what you want?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-03-02 : 02:41:04
|
quote: Originally posted by hamid.y no no.i want adopt something like for statement in interface programming.i want select records of table1 where is equal with one by one records of table2.thats it
Did you try running the queries?Dont assume anything without running themMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|