|
|
|
Custom Search
| |
|
| |
|
Using Comparison Operators, Part I
Comparison operators are used in WHERE clause that compare one expression to another. Read Prerequisites for this tutorial and practices if you haven't done so. Consider the following facts when using comparison operators in a SELECT statement:
Part I of this tutorial covers the following comparison operators:
Practice #1: Using equal to or less than comparison. 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. /*
Query result set: 18 rows returned Practice #2: Using not equal to comparison 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. /*
Query result set: 2147 rows returned Practice #3: Using NULL-safe comparison <=> is NULL-safe equal to. MySQL Documentation states that <=> operator performs an equality comparison like the = operator, but returns 1 rather than NULL if both operands are NULL, and 0 rather than NULL if one operand is 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. /*
Query result set: Here is the query by using equal (=) operator. The result is different. /*
Query result set: Practice #4: Using NULL-safe comparison to get the top employee (Vice President, Sales) 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. /*
Query result set - 1 row returned Here is the query by using equal (=) operator. The result is different. /*
Query result set - 0 rows returned Practice #5: Use ROW constructor for comparison in WHERE clause ROW constructor is used to compare if two or more columns in a table are equal to a row of values. The following query demonstrates the use of ROW constructor to compare a row of values. It's normally used in a query where a subquery returns a row of values. 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. /*
Query result set - 1 row 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 |