Jump to content

Combinaton Where Clause


son
 Share

Recommended Posts

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

A logical OR condition is true as long as any of the two operands evaluate to true.Give 1 as the category_id:

  1. The first condition evaluates to false: category_id != 1 is false because category_id is actually 1
  2. However, the second condition evaluates to true: category_id != 3 is true, because 1 != 3
  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.

Edited by Ingolme
Link to comment
Share on other sites

A logical OR condition is true as long as any of the two operands evaluate to true.Give 1 as the category_id:
  1. The first condition evaluates to false: category_id != 1 is false because category_id is actually 1
  2. However, the second condition evaluates to true: category_id != 3 is true, because 1 != 3
  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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...