Advertisements

Regarding a simple mysql query

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

Offline
webdevoman
Posts: 2
Joined: Tue Sep 08, 2009 1:34 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

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

Offline
webdevoman
Posts: 2
Joined: Tue Sep 08, 2009 1:34 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',

You can use IN clause

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

Offline
remotedba
Posts: 7
Joined: Mon Jan 16, 2012 10:20 pm
You can use IN clause as well for this query

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

Offline
ajitpaswan
Posts: 11
Joined: Mon Dec 24, 2012 2:41 am
Location: India
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)