-1

![enter image description here][1]

my MSSQL table has these properties - id1, id2, isVerified, isRejected, score1, score2, score3. I want to show top1 value where isveried == 1, isRejected==0. After that my first priority is score1. If score1 ties with any other, then 2nd priority is score2, if score2 ties, 3rd priority is score3. The higher the number, the higher the priority. what will be the query? please help.

s6r
  • 27
  • 4
  • Sample data, expected results, and **importantly** *your* attempts will help us help you. What do you mean by the table has those properties? Are you talking about the [extended properties](https://www.red-gate.com/simple-talk/sql/database-delivery/reading-writing-creating-sql-server-extended-properties/) (I doubt it)? Do you *actually* mean a column. A Property, in SQL Server, is completely different to a Column. – Thom A Sep 23 '20 at 14:00
  • Don't post images of text... Paste the text as `text`; that is what it is after all. – Thom A Sep 23 '20 at 14:09
  • Thank you for your kind reply! I have found my answer! :D – s6r Sep 23 '20 at 14:16

1 Answers1

1

I suspect that you want:

select top (1) *
from mytable
where isverified = 1 and isrejected = 0
order by score1 desc, score2 desc, score3 desc

The query filters on verified and non-rejected rows. Then, we keep the row that has the highest score1; if there are ties, we compare score2, and then score3.

GMB
  • 216,147
  • 25
  • 84
  • 135