What is the meaning of <> in mysql query?
MysqlSqlMysql Problem Overview
I have a MySQL query that includes <> in it. I don't know the exact usage of it.
SELECT * FROM table_laef WHERE id = ? AND genre_type <> 'LIVE'
P.S.: Im sorry for this basic syntax, since I have searched for this on Google. All they give is about <=>. Thanks anyway, guys!
Mysql Solutions
Solution 1 - Mysql
<>
is standard ANSI SQL and stands for not equal or !=
.
Solution 2 - Mysql
<>
means not equal to, !=
also means not equal to.
Solution 3 - Mysql
<>
means NOT EQUAL TO, !=
also means NOT EQUAL TO. It's just another syntactic sugar. both <>
and !=
are same.
The below two examples are doing the same thing. Query publisher table to bring results which are NOT EQUAL TO <> !=
USA.
SELECT pub_name,country,pub_city,estd FROM publisher WHERE country <> "USA";
SELECT pub_name,country,pub_city,estd FROM publisher WHERE country != "USA";
Solution 4 - Mysql
In MySQL, I use <>
to preferentially place specific rows at the front of a sort request.
For instance, under the column topic
, I have the classifications of 'Chair', 'Metabolomics', 'Proteomics', and 'Endocrine'. I always want to list any individual(s) with the topic 'Chair', first, and then list the other members in alphabetical order based on their topic
and then their name_last
.
I do this with:
SELECT scicom_list ORDER BY topic <> 'Chair',topic,name_last;
This outputs the rows in the order of:
Chair
Endocrine
Metabolomics
Proteomics
Notice that topic <> 'Chair'
is used to select all the rows with 'Chair' first. It then sorts the rows where topic = Chair
by name_last
.*
*This is a bit counterintuitive since <>
equals !=
based on other feedback in this post.
This syntax can also be used to prioritize multiple categories. For instance, if I want to have "Chair" and then "Vice Chair" listed before the rest of the topics, I use the following
SELECT scicom_list ORDER BY topic <> 'Chair',topic <> 'Vice Chair',topic,name_last;
This outputs the rows in the order of:
Chair
Vice Chair
Endocrine
Metabolomics
Proteomics
Solution 5 - Mysql
In MySQL, <>
means Not Equal To, just like !=
.
mysql> SELECT '.01' <> '0.01';
-> 1
mysql> SELECT .01 <> '0.01';
-> 0
mysql> SELECT 'zapp' <> 'zappp';
-> 1
see the docs for more info
Solution 6 - Mysql
<>
is equal to !=
i.e, both are used to represent the NOT EQUAL operation. For instance, email <> ''
and email != ''
are same.
Solution 7 - Mysql
I know im late to the game but maybe this will help somebody... this is not true even though everyone wrote it <> is equal to != it actually is less than or greater than the exception is with NULL
column <> 3 will not get null columns column != 3 will get null columns
and != is deprecated... hope it helps