What is the meaning of <> in mysql query?

前端 未结 6 1345
醉酒成梦
醉酒成梦 2020-12-28 12:13

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\'
<         


        
相关标签:
6条回答
  • 2020-12-28 12:20

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

    Documentation

    0 讨论(0)
  • 2020-12-28 12:26

    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

    0 讨论(0)
  • 2020-12-28 12:26

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

    0 讨论(0)
  • 2020-12-28 12:29

    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

    0 讨论(0)
  • 2020-12-28 12:39

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

    0 讨论(0)
  • 2020-12-28 12:42

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

    0 讨论(0)
提交回复
热议问题