son Posted August 1, 2009 Share Posted August 1, 2009 I try to get all data displayed other than two ids. My query is:SELECT category_id, parent_id, category FROM categories WHERE category_id != 1 OR category_id != 3 ORDER BY parent_idHow do you actually have a working query that actually discards category_id 1 and 3. This one displays them all and only works when I take the OR out...Son Link to comment Share on other sites More sharing options...
Ingolme Posted August 1, 2009 Share Posted August 1, 2009 A logical OR condition is true as long as any of the two operands evaluate to true.Give 1 as the category_id: The first condition evaluates to false: category_id != 1 is false because category_id is actually 1 However, the second condition evaluates to true: category_id != 3 is true, because 1 != 3 Now that you have the answers to the two conditions, evaluate them with the OR operator:true OR falseSince at least one of them is true when category_id = 1, the row is taken. Use the AND operator instead:if category_id is not 1 AND it is not 3, then select the row. Link to comment Share on other sites More sharing options...
son Posted August 1, 2009 Author Share Posted August 1, 2009 A logical OR condition is true as long as any of the two operands evaluate to true.Give 1 as the category_id:The first condition evaluates to false: category_id != 1 is false because category_id is actually 1 However, the second condition evaluates to true: category_id != 3 is true, because 1 != 3 Now that you have the answers to the two conditions, evaluate them with the OR operator:true OR falseSince at least one of them is true when category_id = 1, the row is taken. Use the AND operator instead:if category_id is not 1 AND it is not 3, then select the row. Got you and have it working asSELECT category_id, parent_id, category FROM categories WHERE (category_id != 1 AND category_id != 3) ORDER BY category_idMany thanks,Son Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.