Share
, ,

MySQL: Advanced Filtering with AND, OR

  • For multiple conditions the use of statement AND-
    SELECT name, state, city FROM customers WHERE state='CA' AND city='Hollywood'
  • For multiple conditions the use of statement OR-
    SELECT name, state, city FROM customers WHERE state='CA' OR city='Hollywood'
  • Use statement AND, OR in the same query-
    SELECT name, state, city FROM customers WHERE id=2 OR id=5 AND state='CA'
  • Make query true for all conditions in the same order-
    SELECT name, state, city FROM customers WHERE (id=2 OR id=5) AND state='CA'



Notice:
  1. We will use statement AND when we want all the test should be true for the query.
  2. We will use statement OR when we want any one of the test should be true for the query.
  3. We can use AND, OR in the same query.
  4. We can use parentheses in the query if we want a portion of the query should be true.
                                      
                                   

0 comments:

Post a Comment