Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

And OR in same column in sql server

I have a simple table in SQL server 2008.

SELECT TOP lastupdated, remarks   FROM table

I want to select the following criteria.

if remarks is 'Others' and DATEDIFF(MINUTE, LastUpdated, GETDATE() ) > 15 then select these rows

Additionally, I want to select following in the same query if remarks is not 'Others'
then select these rows without waiting for 15 minutes

like image 531
Usman Asif Avatar asked Mar 10 '26 16:03

Usman Asif


1 Answers

You can do the following:

select LastUpdated, Remarks
from table
where (remarks = 'Others' and datediff(min, LastUpdated, GETDATE()) > 15)
      or remarks != 'Others'

You can adjust the TOP x, according to your needs, since you didn't put it in your question so I didn't know how many rows you needed to select.

like image 113
Rigerta Avatar answered Mar 13 '26 10:03

Rigerta