Manoj venk
Manoj venk

Reputation: 863

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!

Upvotes: 79

Views: 177920

Answers (7)

juergen d
juergen d

Reputation: 204766

<> is Standard SQL and stands for not equal or !=.

Upvotes: 123

amichaiz
amichaiz

Reputation: 9

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

hope it helps

Upvotes: 0

Nithya Rajan
Nithya Rajan

Reputation: 4884

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

Upvotes: 11

Arun Kumar N
Arun Kumar N

Reputation: 1669

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

Upvotes: 1

cdherold
cdherold

Reputation: 69

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

Upvotes: 4

Raman Sahasi
Raman Sahasi

Reputation: 31851

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

Upvotes: 2

Reece Kenney
Reece Kenney

Reputation: 2964

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

Documentation

Upvotes: 12

Related Questions