Reputation: 161
I'm just checking whether any student has got 35 marks in any subject. Is there any way to simplify it like this where (phy,che,math,cs,eng) in (35)?
with temp_table as(
select "studentA" name,36 as phy, 67 as che,75 math,65 cs,64 eng union all
select "studentB" name,44, 57, 37, 73, 57 union all
select "studentC" name,94, 87, 48, 72, 63
)
select * from temp_table where phy=35 or che=35 or math=35 or cs=35 or eng=35
Upvotes: 0
Views: 812
Reputation: 33705
with temp_table as(
select "studentA" name,36 as phy, 67 as che,75 math,65 cs,64 eng union all
select "studentB" name,44, 57, 37, 73, 57 union all
select "studentC" name,94, 87, 48, 72, 63
)
select * from temp_table where 35 IN (phy, che, math, cs, eng)
(Be aware that if any of the columns is NULL
, however, the IN
comparison will return NULL
)
Upvotes: 1