SQL – Difference between != and <> Operator used for NOT EQUAL TO Operation

Here is interesting question received on my Facebook page. (On a side note, today we have crossed over 50,000 fans on SQLAuthority Facebook Fan Page).

What is the difference between != and <>Operator in SQL Server as both of them works same for Not Equal To Operator? 

SQL - Difference between != and <> Operator used for NOT EQUAL TO Operation Not-Equal-To-Operator

Very interesting question indeed. Even though this looks very simple when I asked quite a few people if they know the answer before I decided to blog about it. The answer which I received was that it seems that many know the answer but everybody wanted to know the more about it.

Here is the answer – Technically there is no difference between != and <>. Both of them work the same way and there is absolutely no difference in terms of performance or result.

Here is the follow up question I received right I answer that there is no difference between those operator.

If != and <> both are the same, which one should be used in SQL queries?

Here is the answer – You can use either != or <> both in your queries as both technically same but I prefer to use <> as that is SQL-92 standard.

Though, many of the leading database applications supports both of the operators. For example –

  • SQL Server
  • MySQL
  • Oracle
  • SQLite
  • Sybase
  • IBM Informix
  • PostgreSQL

Here is my return question to you which one of the following operators you use for NOT EQUAL TO operation?

  1. !=
  2. <>

Please leave your answer with reason in comment field and I will publish the interesting answer as a follow up blog post with due credit.

Reference: Pinal Dave (https://blog.sqlauthority.com)

Previous Post
SQL SERVER – Check Database Level (IsNullConcat) and Session Level Settings (CONCAT_NULL_YIELDS_NULL) using T-SQL
Next Post
SQL – Download Database Cheat Sheet for MongoDB, NuoDB, MySQL for FREE

Related Posts

No results found.

59 Comments. Leave new

  • I use

    Reply
  • John Paul Cook
    July 8, 2013 7:32 am

    There is a difference. != is not ANSI compliant. Use for ANSI compliance.

    Many people mistakenly believe that ANSI compliance is not important. In SQL 2014, old style non-ANSI joins simply won’t work.

    Also, deprecated syntax may work, but that doesn’t mean it works well. When deprecated syntax is used, you aren’t taking advantage of all of the latest and greatest enhancements to the SQL engine. It’s important to keep up with the standards and make an effort to write good, modern code.

    Reply
    • Just to give flexibility to the developer SQL server supports != (though it is not an ANSI standard).

      Reply
  • one more reason
    is easy to type :-)

    Reply
  • I generally use <> , but when posting comment here, I have to use !=

    Reply
  • I use .

    That’s what I was taught at school when learning maths and it stuck!

    Only since learning C# have I started using ‘!’ for ‘not’, but not in T-SQL.

    Reply
  • kalyanasundaram
    July 8, 2013 11:52 am

    For Not equal to operation :

    For programming i am using front end applications for Equal (==) and Not Equal (!=)
    But in back end application SQL server using Equal (=) and Not Equal ()

    Reply
  • I am using

    Reply
  • I prefer ANSI, so I use

    Reply
  • Dinesh Maurya
    July 8, 2013 12:59 pm

    BM DB2 UDB 9.5: supports only .

    Reply
  • When any query calling from any application then it must be use [!=] as will be like HTML tag and this may be harmful during sending/receiving data to/from server.

    Reply
  • Smiju A. Antony
    July 8, 2013 2:21 pm

    fraction of a second!

    Reply
  • We use != it comes first hand as it’s commonly used in Java as well.

    Reply
  • M.G Jayasundara (@starmalidu)
    July 8, 2013 5:40 pm

    I’m generally using operator and some times i used !=

    Reply
  • I personally use . I did notice that that when you view the XML for an SSRS .RDL file the is transformed to <> while the != is not. Using != can be useful when writing SQLfor SSRS datasets and you need to extract the SQL right out of the RDL file at a later time.

    Reply
  • Back when i was Programming C++ i used the ! operator.
    Lately i was doing a lot of VB programming and so mostly used the in my sql statements.

    Reply
  • practicaldavis
    July 8, 2013 7:56 pm

    I generally use != because it’s slightly easier to read, coming from a programming background it makes me spend slightly less time thinking about what it means. (! means not, and = means equal, whereas <> stops me for a moment.

    I still use them both though.

    Reply
  • Steve Harris
    July 8, 2013 9:14 pm

    Even though both are, technically, the same, I would use the != operator, because is too much like HTML or XML. Confusion with other apps could occur (you just never know!).

    Reply
  • I’ve been using bang-equal these many years because my first programming language (after some TRS-80 BASIC) was C (where bang is both a logical and a bitwise NOT and, to my humble mind, is a sensible prefix for the EQU operator when you’re trying to say NOT(EQU)). In T-SQL, I often use NOT(…) (e.g. NOT EXISTS, NOT(this AND that), etc.), so bang-equal again is a sensible equivalent for NOT( something EQU something). Even before angle brackets were utilized for HTML (later, XML), some parser Out There might have confused left_angle-right_angle with some other construct and not considered it to mean NEQ….

    Reply
  • I find I use both. If I am doing several “=” operators, I usually use “!=”, maybe just out of habit? However if went straight in looking for not equal, I’d use “”

    Reply
  • I always use because it is easy to use.
    ANSI stander.
    As early discuss that both work same.
    SQL is facilitate its user to use both syntax !=, .net as well as html :)

    Reply

Leave a Reply