20

What is the exact Difference between <> and != ?

Vijjendra
  • 22,463
  • 11
  • 57
  • 90
  • I don't think there is, but you might want to be more specific about the sql dialect ... ANSI SQL (year?), Oracle, MS T-SQL, DB2, MySql, ...? – Vik David May 02 '11 at 11:24
  • 6
    Related: http://stackoverflow.com/questions/723195/should-i-use-or-for-not-equal-in-tsql/723426#723426 – Joachim Sauer May 02 '11 at 11:25
  • Why this question should be close? – Vijjendra May 02 '11 at 11:28
  • Well, the reason given for closing it is "not a real question". I don't see what justification there is for that, as it seems a pretty straight-forward question. If it's closed for that reason, I for one will be voting to re-open. – Jon Hanna May 02 '11 at 22:10

6 Answers6

15

None whatsoever, syntactically.

Both are inequality operators, <> is the SQL-92 standard, however its interchangable on some platforms with != (E.g. SQL Server)

Alex K.
  • 165,803
  • 30
  • 257
  • 277
3

<> is the only inequality operator in the SQL Standard.

Lot's of SQL database systems support the use of != including PostgreSQL, SQL Server, MySQL, SQLite, Oracle & Firebird, but some don't, including Apache Derby.

Jon Hanna
  • 106,895
  • 9
  • 141
  • 243
1

In Oracle there is no difference. Can't speak for all other databases.

TedTrippin
  • 3,425
  • 4
  • 24
  • 44
  • 7
    @Vijjendra: When you say "SQL" it may be that you mean "Microsoft SQL Server", but to many of us "SQL" is a query language supported by many database products, among them Oracle, PostgreSQL, MySQL, Firebird, Rdb, Microsoft Access, and many others. – Bob Jarvis - Слава Україні May 02 '11 at 11:37
1

There is no difference, at least for MySQL.

See: http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html

Frosty Z
  • 21,350
  • 10
  • 81
  • 110
1

Both are used in SQL Server. Both are used for same purpose. SQL Server 2000 and its previous version don't support != but SQL Server 2005 and SQL Server 2008 supports both <> and !=

Pankaj Agarwal
  • 10,965
  • 12
  • 40
  • 58
1

Functionally there's no difference.

I think this is a matter of programmer preference: '<>' may be preferred by programmers who use various flavors of Pascal or Basic, while '!=' may be preferred by those who use languages which are descendants of C (e.g. C++, Java, C#). Interestingly, though, the C-style equality comparison operator ('==') is not supported in Oracle - how about in other flavors of SQL?

Share and enjoy.