sw9 Posted April 17, 2008 Share Posted April 17, 2008 Hi All, I am having a bit of newbie trouble writing a nested mysql statement that has multiple conditions. The issue I'm having is in the WHERE clause. I'm on mysql 5.0.37. Here's what I am trying to do: The first two conditions in my WHERE clause MUST be met, while only 1 of the last three conditions must be met. It is working well except it's not following my TIMESTAMP rule and is instead returning all results regardless of if TIMESTAMP(cp.field_pdate_value) <= NOW(). I thought that putting the first two conditions within a set of parantheses was the way to do it, but I'm obviously wrong. Can anyone point me in the right direction? SELECT NOW(), cp.nid, TIMESTAMP(cp.field_pdate_value), n.title FROM content_type_content_program cp LEFT JOIN node n ON (n.nid = cp.nid) LEFT JOIN term_node tn ON (cp.nid = tn.nid) JOIN term_data td ON (tn.tid = td.tid) WHERE (tn.tid = (SELECT td.tid FROM term_data td WHERE td.name = 'Burlington' AND td.vid = '31') AND TIMESTAMP(cp.field_pdate_value) <= NOW() ) AND td.tid = '312' OR td.tid = '221' OR td.tid = '222' ORDER BY cp.field_pdate_value DESC Thanks much in advance! Link to comment https://forums.phpfreaks.com/topic/101586-solved-where-andor-conditionals-newbie-question/ Share on other sites More sharing options...
fenway Posted April 17, 2008 Share Posted April 17, 2008 Replace this: AND td.tid = '312' OR td.tid = '221' OR td.tid = '222' with this: AND ( td.tid = '312' OR td.tid = '221' OR td.tid = '222' ) or even better: AND td.tid IN ( '312' , '221' , '222' ) Link to comment https://forums.phpfreaks.com/topic/101586-solved-where-andor-conditionals-newbie-question/#findComment-519693 Share on other sites More sharing options...
sw9 Posted April 18, 2008 Author Share Posted April 18, 2008 Thank you; this worked perfectly. I appreciate the help! Link to comment https://forums.phpfreaks.com/topic/101586-solved-where-andor-conditionals-newbie-question/#findComment-520415 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.