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
 Old Forums
 CLOSED - General SQL Server
 [SQL] how to SELECT multiple IDS from a table?

Author  Topic 

dionisio
Starting Member

2 Posts

Posted - 2006-01-30 : 02:05:17
If someone can suggest me how to do a query like that

SELECT id,name from mytable WHERE ( id='1' OR id='2' OR id='9' );

From what I can suppose it's not the best way to select multiple ids from the table, how can I do it in a smarter way?

thank you

shallu1_gupta
Constraint Violating Yak Guru

394 Posts

Posted - 2006-01-30 : 02:14:36
Use In Clause
SELECT id,name from mytable WHERE id in (1,2,9,.. );
Go to Top of Page

dionisio
Starting Member

2 Posts

Posted - 2006-01-30 : 02:38:46
tnx
Go to Top of Page
   

- Advertisement -