Strange SQL problem selecting multiple values for same column

Posted by Nubber on Stack Overflow See other posts from Stack Overflow or by Nubber
Published on 2010-02-23T01:22:08Z Indexed on 2010/05/29 7:02 UTC
Read the original article Hit count: 119

Filed under:

Hello there,

Been at this for a few hours now and I can't make any sense of it. I've used this way of selecting multiple values for same column a few times, but there is something weird with this one.

SELECT * FROM employee as s
INNER JOIN works AS w1 ON w1.name = s.name
INNER JOIN employee AS w2 ON w2.name = s.name
INNER JOIN employee AS w3 ON w3.name = s.name
WHERE w2.city = 'Washington'

Basically what I want to do is find all companies which have people in all the cities. The company name is under 'works'. The problem is however that if I have the WHERE w2.city='Washington' it will make ALL the cities match Washington when it should only touch w2 and leave w3 alone so I could match it with another value.

Anyone know why its doing this? Or know a better way to do it.

Thank you very much in advance.

© Stack Overflow or respective owner

Related posts about mysql