Reputation: 434
I have a table of teachers
with the following column
TID, Fname, Lname, Email, uname, pass, grade, subject, start time, end time
The problem is that I want to select those teachers who have the subject of science but here in my subject column there are two values like this:
-------------------
| subject |
-------------------
| maths, science |
-------------------
How would i select only science from this column?
Upvotes: 0
Views: 271
Reputation: 644
you can also use like this
SELECT * FROM [TABLE] WHERE [SUBJECT] IN ( 'Science');
Upvotes: 0
Reputation: 2506
How would i select only science from this column?
Not sure what you actually mean by this but here goes
Get all teachers who teach Science at all
SELECT *
FROM table
WHERE Subject LIKE '%Science%'
Get teachers who teach Science but don't show that they teach Math
SELECT TID, Fname, Lname, 'Science'
FROM table
WHERE Subject LIKE '%Science%'
Get all teachers who only teach Science
SELECT *
FROM table
WHERE Subject = 'Science'
Use whichever you're looking for
Upvotes: 2
Reputation: 306
You could use a wildcard like this
SELECT * FROM [TABLE] WHERE [Subject] LIKE '%Science%'
Hope that helped
Upvotes: 3