Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > basic SQL question...

basic SQL question...
Thread Tools
Fresh-Faced Recruit
Join Date: Apr 2005
Status: Offline
Reply With Quote
Apr 10, 2005, 03:57 PM
 
Hi,

THis is a very basic question, but I can't remember how to write the statement for MySQL.

I'd like to query my MySQL database, table XYZ, and retrieve all records with id = 1, 20, 15, 7, and 3. In psuedo-code it might look like:

select * from XYZ where id = [1,20,15,7,3]

What would this query look like for a MySQL database?

Thanks

-R
     
rosslyn  (op)
Fresh-Faced Recruit
Join Date: Apr 2005
Status: Offline
Reply With Quote
Apr 10, 2005, 04:29 PM
 
Sorry for such a silly question. I fiddled around with the code and realized that this worked just fine:

select * from XYZ where id = (1,20,15,7,3)

Thanks for your patience.

-r
     
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status: Offline
Reply With Quote
Apr 12, 2005, 11:20 AM
 
Originally posted by rosslyn:
Sorry for such a silly question. I fiddled around with the code and realized that this worked just fine:

select * from XYZ where id = (1,20,15,7,3)

Thanks for your patience.

-r
That's not really correct SQL syntax. It may have worked, but the correct form would be:

Code:
SELECT * FROM XYZ WHERE id IN (1,20,15,7,3)
Mac Pro 2x 2.66 GHz Dual core, Apple TV 160GB, two Windows XP PCs
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 07:24 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2