|
Custom Search
| |
|
Using Logical Operators Logical operators enable us to use more than one condition in WHERE clause. Read Prerequisites for this tutorial and practices if you haven't done so. List of logical operators in MySQL:
Consider the following facts when using logical operators in a SELECT statement:
Most of the queries in the tutorials need Northwind MySQL database, you can download the database script on this page. Practice #1: Using AND operator. /* AND (&&) operator requires both conditions to be TRUE.
Query result set - 3 rows returned: AND Truth Table The following table shows the result of comparing two expressions with AND operator:
Practice #2: Using OR operator /* OR (||) operator requires either condition to be TRUE.
Query result set - 24 rows returned: OR Truth Table The following table shows the result of comparing two expressions with OR operator:
Practice #3: Use NOT BETWEEN...AND... -- List products which unit price is not
Query result set - 2 rows returned: Practice #4: Use NOT IN (value1, value2, value3, ...) -- List products which reorder level is not
Query result set - 8 rows returned: Practice #5: Use NOT LIKE -- Retrieve all products which product
Query result set - 68 rows returned: Practice #6: Use NOT NULL -- Find all the employees who have someone
Query result set - 8 rows returned: Practice #7: Use XOR operator /* The two queries return the same result.
Query result set - 4 rows returned: Other tutorials in this category 1. The Basic SELECT Statement |
Copyright © 2024 GeeksEngine.com. All Rights Reserved. This website is hosted by HostGator. No portion may be reproduced without my written permission. Software and hardware names mentioned on this site are registered trademarks of their respective companies. Should any right be infringed, it is totally unintentional. Drop me an email and I will promptly and gladly rectify it. |
Home | Feedback | Terms of Use | Privacy Policy |