Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
bdeonline
Forum Commoner
Posts: 42 Joined: Sun Jul 18, 2004 10:45 am
Post
by bdeonline » Fri Aug 20, 2004 11:13 am
I need a query that can retreieve more than one id.
Code: Select all
SELECT color FROM color WHERE id='2, 4, 1'
hawleyjr
BeerMod
Posts: 2170 Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA
Post
by hawleyjr » Fri Aug 20, 2004 11:13 am
Code: Select all
SELECT color FROM color WHERE id=2 or id=4 or id = 1
bdeonline
Forum Commoner
Posts: 42 Joined: Sun Jul 18, 2004 10:45 am
Post
by bdeonline » Fri Aug 20, 2004 11:15 am
Thanks I knew it was something super simple but the simple answers are the hardest ones to find on google.
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Fri Aug 20, 2004 11:20 am
Or:
SELECT color FROM color WHERE FIND_IN_SET(id, '1,2,4');
fractalvibes
Forum Contributor
Posts: 335 Joined: Thu Sep 26, 2002 6:14 pm
Location: Waco, Texas
Post
by fractalvibes » Fri Aug 20, 2004 9:37 pm
Or
select color from color where id in ('1','2','3')
(standard sql)
Depending on DBMS, you could also have the where clause reference the return value of a subselect if you need to qualify that group of ids rather than hard-coding them...
fv