Master
Master

Reputation: 425

Display any value instead of null?

Code:

use tennis;
select playerno, name, initials,leagueno,
case 
when leagueno = null then 1 
end
from players
where tennis.players.town = 'Stratford'
order by leagueno desc;

Please help me to do it correctly. I have the answer which uses coalesce. But i want to try another method.

Upvotes: 0

Views: 240

Answers (1)

Brendan Long
Brendan Long

Reputation: 54312

I think what you want is this:

use tennis;

select playerno, name, initials,
case 
when leagueno is null then 1 -- note: is null instead of = null
else leagueno
end as leagueno -- This names the result column "leagueno", which may be useful
                -- depending on how you read the result
from players
where tennis.players.town = 'Stratford'
order by leagueno desc;

This basically makes the last column leagueno except that if it's NULL, you get 1 instead.

Upvotes: 1

Related Questions