[mysql] What is the meaning of <> in mysql query?

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!

This question is related to mysql sql

The answer is


<> 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";


<> is equal to != i.e, both are used to represent the NOT EQUAL operation. For instance, email <> '' and email != '' are same.


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


<> means not equal to, != also means not equal to.

Documentation


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