Muhammad Yawar
Muhammad Yawar

Reputation: 434

Select 1 value from 1 column

I have a table of teachers with the following column

TID, Fname, Lname, Email, uname, pass, grade, subject, start time, end time

enter image description here

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

Answers (3)

Dharani Dharan
Dharani Dharan

Reputation: 644

you can also use like this

SELECT * FROM [TABLE] WHERE [SUBJECT] IN ( 'Science');

Upvotes: 0

cameronjonesweb
cameronjonesweb

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

P. Janowski
P. Janowski

Reputation: 306

You could use a wildcard like this

SELECT * FROM [TABLE] WHERE [Subject] LIKE '%Science%'

Hope that helped

Upvotes: 3

Related Questions