1

I have a table like

id  colA  ColB  ColC  COlD 
1   10    Null  Null  100 
2   Null  2     Null  200 
3   Null  Null  7     500

and so on

what i need is if i select the values from the table like

select * from Table where ColC = 7 or ColB = 2 or ColA = 10

i will get the resul as

10    Null   Null 100
Null  2      Null 200
Null  Null   7    500

but i want the result as

Null  Null  7    500
Null  2     Null 200
10    Null  Null 100 

So i could select value of ColD from top row only if the ColC is not null else if ColB is not null else ColA is not null

1
  • Can you explain what the difference between your actual and expected results are? Looks to me like they are just ordered by the last column descending. Commented Jul 20, 2013 at 3:51

1 Answer 1

2

Try this

select * 
from Table 
where ColC = 7 or ColB = 2 or ColA = 10
ORDER BY ColC DESC, ColB DESC, ColA DESC
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.