I have three columns in a table:
score status No.
1, 2, 1
0, 1, 2
0, 0, 1
I need this to write an SQL C # alias:
rows = empty;
rows = "SELECT * FROM `table` WHERE score = 1"
if (rows.Count > 0)
return rows;
rows = "SELECT * FROM `table` WHERE status = 2"
if (rows.Count > 1)
return row with MAX(No.) from rows;
return rows;
Hope I could be clear. In short, select from my table entries with a score of = 1, and if there is no such record, return the record where status = 2, and if there is more than one record with status = 2, return the record with the maximum value for No., where status = 2 (if there is no record at all with status = 2, return empty).
How can I write it in one query? It should be a good learning experience for me. Otherwise, I know to break up small queries and run them. And I can't go with stored procedures right now.
: WHERE, , . , . SELECT * FROM table WHERE score = 1 . / , . , , , score = 1. . - , score = 1. . , , , .
: , , :) , . :
, : @GordonLinoff's, @ZaneBiens, @ZaneBien , @Scen's, @JulienCh.'s ( 3 , , :))
, , score = 1 : @HannoBinder, @ShlomiNoach's, @ -. @Danielle ( ), , )
, , , MySQL.
@MatthewPK .
. , , , , , @Scen answer .