Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is difference between != and <> in sql server [duplicate]

What is difference between != and <> operators in Sql Server?

Since both are used as not operator. E.g :

select * from TableName where ColName <> value 

or

select * from TableName where ColName != value 

returns same values (Rows).

like image 501
Ankush Madankar Avatar asked Aug 02 '13 11:08

Ankush Madankar


People also ask

What is difference between != and <> in SQL?

Difference between SQL Not Equal Operator <> and != to do inequality test between two expressions. Both operators give the same output. The only difference is that '<>' is in line with the ISO standard while '!= ' does not follow ISO standard.

Is != Or <> better in SQL?

Both are valid, but '<>' is the SQL-92 standard.

What does != Mean in SQL Server?

Not Equal Operator: != Evaluates both SQL expressions and returns 1 if they are not equal and 0 if they are equal, or NULL if either expression is NULL. If the expressions return different data types, (for instance, a number and a string), performs type conversion.

What does <> symbol mean in SQL?

More Detail. The symbol <> in MySQL is same as not equal to operator (!=). Both gives the result in boolean or tinyint(1). If the condition becomes true, then the result will be 1 otherwise 0.


2 Answers

There is no difference. You can use both in MSSQL.

The MSSQL doc says:

!= functions the same as the <> (Not Equal To) comparison operator.

But <> is defined in the ANSI 99 SQL standard and != is not. So not all DB engines may support it and if you want to generate portable code I recommend using <>.

like image 138
juergen d Avatar answered Oct 20 '22 01:10

juergen d


Most of the databases support both != and <> as not equal comparison operators. <> means either less than or greater than (i.e. not equal to) and was introduced because not all the keyboards used to have the exclamation ! key (a long time ago). Some databases like Oracle also support ^= for not equals.

like image 28
Ravi K Thapliyal Avatar answered Oct 20 '22 00:10

Ravi K Thapliyal