NoDoze Posted April 1, 2009 Share Posted April 1, 2009 SELECT * FROM publications WHERE type='presentation' AND type='publication' AND keyw='groundwater' ORDER BY pubdate DESC WHERE? AND? How would I do this type of query? I can't find anything on google or even this forum about multiple WHERE queries... Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/152142-where-where-where/ Share on other sites More sharing options...
Mchl Posted April 1, 2009 Share Posted April 1, 2009 Most likely you need OR not AND Think about it. An item cannot be a publication and a presentation at one time. SELECT * FROM publications WHERE (type='presentation' OR type='publication') AND keyw='groundwater' ORDER BY pubdate DESC Quote Link to comment https://forums.phpfreaks.com/topic/152142-where-where-where/#findComment-799033 Share on other sites More sharing options...
NoDoze Posted April 1, 2009 Author Share Posted April 1, 2009 Hmmm...ok..it worked... I was thinking...I'm trying to pull all presentations AND publications from the type column...hence it's be AND...but since you worded it that way... Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/152142-where-where-where/#findComment-799037 Share on other sites More sharing options...
Mchl Posted April 1, 2009 Share Posted April 1, 2009 SQL grammar is a bit diffrent Imagine that you take one row from a table at a time, and check if it matches conditions. You find a row that has type = 'presentation' If the condition is: type='presentation' AND type='publication' you say: 'let's see.. hmm.. the type is 'presentation' fine... now I check another part of condition... oops... the type is not 'publication', this row does not match criteria If the condition is: type='publication' OR type='presentation' you say: 'let's see.. hmm.. the type is not 'publication' but there's another condition, let's check it... the type can also be 'presentation'.. it is! this row matches criteria This post was brought to you by late night SQL stories. Quote Link to comment https://forums.phpfreaks.com/topic/152142-where-where-where/#findComment-799041 Share on other sites More sharing options...
Andy-H Posted April 1, 2009 Share Posted April 1, 2009 SQL grammar is a bit diffrent Imagine that you take one row from a table at a time, and check if it matches conditions. You find a row that has type = 'presentation' If the condition is: type='presentation' AND type='publication' you say: 'let's see.. hmm.. the type is 'presentation' fine... now I check another part of condition... oops... the type is not 'publication', this row does not match criteria If the condition is: type='publication' OR type='presentation' you say: 'let's see.. hmm.. the type is not 'publication' but there's another condition, let's check it... the type can also be 'presentation'.. it is! this row matches criteria This post was brought to you by late night SQL stories. LMAO, I like that, good sense of humour. Helps make learning a little less boring =D Quote Link to comment https://forums.phpfreaks.com/topic/152142-where-where-where/#findComment-799047 Share on other sites More sharing options...
NoDoze Posted April 2, 2009 Author Share Posted April 2, 2009 hehe...funny... Now I have an additional question...kinda related.... I also have a column for keywords (keyw) with entries like, on some rows: bh nn ds bdb bkh another row bh ds another row bdb I want the query to pull up all records that have bh in the keyw, how would I do this? Cause right now with a query for bh, it's not pullin up anything cause it sees the entire row 'bh nn ds bdb bkh' as a value. WHERE type='report' AND keyw='bh' Would I use %bh%, or bh%...? But neither of those pull up anything either.... Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/152142-where-where-where/#findComment-799873 Share on other sites More sharing options...
NoDoze Posted April 2, 2009 Author Share Posted April 2, 2009 ok, I THINK is figured it out... WHERE keyw REGEXP 'bh' Is that right? Seams to pull up the correct info.... Quote Link to comment https://forums.phpfreaks.com/topic/152142-where-where-where/#findComment-799884 Share on other sites More sharing options...
xtopolis Posted April 3, 2009 Share Posted April 3, 2009 % is usually used for LIKE conditions. SELECT ... FROM ... WHERE column LIKE 'bh%'; -anything that starts with bh and has anything or nothing after it. Quote Link to comment https://forums.phpfreaks.com/topic/152142-where-where-where/#findComment-800036 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.