I am new to mySql and am trying to do a filtering query from one column using data from a few other tables. For example, I can pull a table of names, a table of their marks in the sports classes, and a table of sports.
I can query this database using
WHERE beta.sport = 'basketball';
pulls all of the beta id's for basketball and effectively all the kids who play basketball. Now I want to find all the kids who played basketball AND Lacrosee.
WHERE beta.sport = 'basketball' AND beta.sport = 'lacrosse';
The problem is that the query executes fine, but returns zero results. I know by manually looking at my data, that there are kids who play basketball and lacrosse. How do you filter the kids who play both basketball and lacrosse? OR returns kids that play either lacrosse or basketball. I only want to return kids that play both and the only access I have to the list of sports is from this one table beta.
TABLE beta
beta_id - sport ||
1 - basketball ||
2 - lacrosse ||
3 - football ||
4 - basketball ||
SELECT *
FROM names n
WHERE (
SELECT COUNT(*)
FROM beta b
WHERE b.sport IN ('basketball', 'lacrosse')
AND b.name = n.id
) = 2