Reputation: 136
I have the following table:
userid title content
1 gender male
1 location NY
2 gender female
2 location SF
3 gender female
3 location NY
I'm trying to retrieve only userid with gender="male" and location="NY"
if I try:
select userid
from table
where content="male"
AND location="NY";
It will return null. Any idea how to do that?
Upvotes: 3
Views: 62
Reputation: 17560
SELECT t.userId
FROM yourTable AS t
INNER JOIN yourTable AS t2 ON t.userId = t2.userId
AND t.title = 'gender'
AND t.content = 'male'
AND t2.title = 'location'
AND t2.content = 'NY'
I would also consider looking at normalizing your data. It would make queries like this much easier (and probably faster) in the future.
Upvotes: 1