I would like to know if there is anyway in sql server to order rows based on which rows meet the conditions first , for example if i am writing a query like this
SELECT * FROM IMAGES
WHERE NAME LIKE '%TEST%'
AND DESCRIPTION LIKE '%TEST%'
I want rows that match the name to appear before rows that match the description , usually sql server will arrange them by their ID , so…anyway to do this ?! (note : I dont want to use union statement as that’s gonna exhaust the database ).
First, the UNION would not necessarily exhaust the database; as written, it might not make a difference at all, performance-wise, depending on how the query optimizer decided to handle it.
Second, as your where clause contains an “AND”, all your results will match on both description and name, so I don’t think that’s what you want.
Third, assuming you meant to have an “OR” in your query, you could try something like this: