Regarding a simple mysql query

Discussion on SQL and MySQL
no avatar
webdevoman
 
Posts: 2
Joined: Tue Sep 08, 2009 1:34 am

Regarding a simple mysql query

by webdevoman » Tue Sep 08, 2009 1:54 am

First off I want to say how great this site is. I will be here often reading the tutorials etc..

My problem is self explanatory really. I am having trouble with the following query. Can anyone help me fix this. I know I have messed up the "where" clause badly...

Code: Select all
SELECT *
FROM userfield AS userfield
LEFT JOIN user AS user ON (user.userid = userfield.userid)
WHERE user.usergroupid = 15 AND user.userfield = 19, 20, 7, 12, 13, 18, 14, 15, 16, 17,


Thanks so much

webdevoman

no avatar
webdevoman
 
Posts: 2
Joined: Tue Sep 08, 2009 1:34 am

by webdevoman » Tue Sep 08, 2009 3:15 am

I think I figured this out.. Is this correct??

Code: Select all
SELECT *
FROM userfield AS userfield
LEFT JOIN user AS user ON (user.userid = userfield.userid)
WHERE user.usergroupid = 15 AND user.userfield = '19' and '20' and '7' and '12' and '13' and '14' and '15' and '16' and '17' and '18',

no avatar
remotedba
 
Posts: 7
Joined: Mon Jan 16, 2012 10:20 pm

You can use IN clause

by remotedba » Mon Jan 16, 2012 10:30 pm

You can use IN clause as well for this query

no avatar
ajitpaswan
 
Posts: 11
Joined: Mon Dec 24, 2012 2:41 am
Location: India

by ajitpaswan » Tue Dec 25, 2012 3:21 am

This should help you :
SELECT *
FROM userfield AS userfield
LEFT JOIN user AS user ON (user.userid = userfield.userid)
WHERE user.usergroupid = 15
AND user.userfield IN(19, 20, 13, 14, 15, 16, 17, 18)

Return to SQL and MySQL

cron