assume my table contains following columns
Roll_number numeric not null
Subject1 varchar(40) null
Subject2 varchar(40) null
. . .
Subject8 varchar(40) null
i have to search a subject in all these subject1 to 8 using SQL Query. what would be the best query to search a substring in all these columns keeping in mind that any one of these can have NULL value.
i wrote
select *
from students_data
where subject1="BIOLOGY" or subject2="BIOLOGY" . . . . or subject8="BIOLOGY"
but i need a simple query because in actual i have more than 20 columns in my table
The query
select * from table1 where "BIOLOGY" in (subject1,subject2,subject3)
was helpful but what if i have to match just the substring (part of that subject) like
“BIO” in that table fields
How about this?
Update 1
For NULL values, use below.
For using BIO, you can use
LIKE '%BIO%';