|
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:
Most of the queries in the tutorials need Northwind MySQL database, you can download the database script on this page. Practice #1: Using equal to or less than comparison. /*
Query result set: 18 rows returned Practice #2: Using not equal to comparison /*
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.
/*
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) /*
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. /*
Query result set - 1 row 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 |