|
|
|
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:
Practice #1: Using AND operator. In Firefox (not IE), copy and paste the following SQL to your SQLyog query window. Note that the SQL needs to end with semi-colon if you have multiple queries in the query window. Most of the queries in the tutorials need Northwind MySQL database, you can download the database script on this page. /* 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 In Firefox (not IE), copy and paste the following SQL to your SQLyog query window. Note that the SQL needs to end with semi-colon if you have multiple queries in the query window. Most of the queries in the tutorials need Northwind MySQL database, you can download the database script on this page. /* 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... In Firefox (not IE), copy and paste the following SQL to your SQLyog query window. Note that the SQL needs to end with semi-colon if you have multiple queries in the query window. Most of the queries in the tutorials need Northwind MySQL database, you can download the database script on this page. -- List products which unit price is not
Query result set - 2 rows returned: Practice #4: Use NOT IN (value1, value2, value3, ...) In Firefox (not IE), copy and paste the following SQL to your SQLyog query window. Note that the SQL needs to end with semi-colon if you have multiple queries in the query window. Most of the queries in the tutorials need Northwind MySQL database, you can download the database script on this page. -- List products which reorder level is not
Query result set - 8 rows returned: Practice #5: Use NOT LIKE In Firefox (not IE), copy and paste the following SQL to your SQLyog query window. Note that the SQL needs to end with semi-colon if you have multiple queries in the query window. Most of the queries in the tutorials need Northwind MySQL database, you can download the database script on this page. -- Retrieve all products which product
Query result set - 68 rows returned: Practice #6: Use NOT NULL In Firefox (not IE), copy and paste the following SQL to your SQLyog query window. Note that the SQL needs to end with semi-colon if you have multiple queries in the query window. Most of the queries in the tutorials need Northwind MySQL database, you can download the database script on this page. -- Find all the employees who have someone
Query result set - 8 rows returned: Practice #7: Use XOR operator In Firefox (not IE), copy and paste the following SQL to your SQLyog query window. Note that the SQL needs to end with semi-colon if you have multiple queries in the query window. Most of the queries in the tutorials need Northwind MySQL database, you can download the database script on this page. /* The two queries return the same result.
Query result set - 4 rows returned:
|
|
Copyright © 2012 GeeksEngine.com. All Rights Reserved. This website is hosted by LunarPages. 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 | Kung Fu Timer | Feedback | Terms of Use | Privacy Policy |