Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Date Query: Is 'not equal' more expensive than 'less than'

Tags:

sql-server

On a date field I have a default value that indicates a non-completion of a task. When I query to find all completed tasks which is better if my default date is 12/31/9999?

SELECT * FROM Table WHERE Completed  <> '12/31/9999'

OR

SELECT * FROM Table WHERE Completed  < '12/31/9999'

Or does it completely depend on my indexing.

like image 548
Nate Avatar asked Dec 04 '25 22:12

Nate


1 Answers

Here are the key operators used in the WHERE clause, ordered by their performance. Those operators at the top will produce results faster than those listed at the bottom.

 =
>, >=, <, <=
LIKE
<>

http://www.sql-server-performance.com/2007/t-sql-where/

like image 157
Min Min Avatar answered Dec 07 '25 15:12

Min Min