21

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

Vijjendra
  • 24,223
  • 12
  • 60
  • 92
  • 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.
  • 171,639
  • 30
  • 264
  • 288
4

<> 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
  • 110,372
  • 10
  • 146
  • 251
1

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

TedTrippin
  • 3,525
  • 5
  • 28
  • 46
  • 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

Maxime Pacary
  • 22,336
  • 11
  • 85
  • 113
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
  • 11,191
  • 12
  • 43
  • 59
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.