liamloveslearning Posted August 6, 2010 Share Posted August 6, 2010 Hi all, I need to query my database where x is y and where x is also z if this makes sense? My query is something similiar to... SELECT * FROM 'x' WHERE x=x AND model_pictures.theme=1 AND model_pictures.theme=3 only it isnt working, Is it possible to have somthing like.. AND model_pictures.theme=3 AND 1? Link to comment https://forums.phpfreaks.com/topic/209980-2-and-commands/ Share on other sites More sharing options...
Adam Posted August 6, 2010 Share Posted August 6, 2010 Your problem is not with the where clause, but SELECT * FROM 'x'. You cannot have quotes around a table name, you need to use grave accents ``. Link to comment https://forums.phpfreaks.com/topic/209980-2-and-commands/#findComment-1095993 Share on other sites More sharing options...
liamloveslearning Posted August 6, 2010 Author Share Posted August 6, 2010 Sorry MrAdam. that was a typo I was just quickly typing x=x for an example. Link to comment https://forums.phpfreaks.com/topic/209980-2-and-commands/#findComment-1095994 Share on other sites More sharing options...
Adam Posted August 6, 2010 Share Posted August 6, 2010 Okay, could you paste the actual SQL you're trying then? Link to comment https://forums.phpfreaks.com/topic/209980-2-and-commands/#findComment-1095996 Share on other sites More sharing options...
PFMaBiSmAd Posted August 6, 2010 Share Posted August 6, 2010 model_pictures.theme=1 AND model_pictures.theme=3 A column can only have a single value at any time. ^^^ Using AND there won't match anything because the value cannot be both 1 and 3 at the same time. You need to use OR to form a union/set of rows that have the values 1 OR 3. Link to comment https://forums.phpfreaks.com/topic/209980-2-and-commands/#findComment-1095998 Share on other sites More sharing options...
liamloveslearning Posted August 6, 2010 Author Share Posted August 6, 2010 nvm didnt realise there was an OR clause! Link to comment https://forums.phpfreaks.com/topic/209980-2-and-commands/#findComment-1096000 Share on other sites More sharing options...
liamloveslearning Posted August 6, 2010 Author Share Posted August 6, 2010 My query is SELECT model_login.id, model_login.username, model_pictures.id, model_pictures.user_id, model_pictures.user_picture, model_pictures.user_picture_date, model_pictures.user_pic_approval FROM model_pictures, model_login WHERE model_pictures.user_id=model_login.id AND model_pictures.user_pic_approval=1 AND model_pictures.theme=1 OR model_pictures.theme=3 Does this seem valid ? Link to comment https://forums.phpfreaks.com/topic/209980-2-and-commands/#findComment-1096001 Share on other sites More sharing options...
Adam Posted August 6, 2010 Share Posted August 6, 2010 You need to wrap model_pictures.theme=1 OR model_pictures.theme=3 within parentheses, so that it will match all the rest and then either one of those two. Link to comment https://forums.phpfreaks.com/topic/209980-2-and-commands/#findComment-1096012 Share on other sites More sharing options...
dix.selken Posted August 8, 2010 Share Posted August 8, 2010 hello I recommend you to use in clause instead of several or clause select * from phones where brand in ('sony ericsson','panasonic','lg') works the same like select * from phones where brand = 'sony ericsson' or brand='panasonic' or brand = 'lg' see ya Link to comment https://forums.phpfreaks.com/topic/209980-2-and-commands/#findComment-1096479 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.