Steve Taylor
Steve Taylor

Reputation: 301

MySQL Query Distinct ID over multiple lines

MySQL table 'Features'

prop_id    name
----------------------------
1          Wifi
2          Off Road Parking
1          Off Road Parking
2          Close to beach
3          Close to Pub
1          Close to Pub

Prop_id is the id in another table of the property

what i would like to do is get the id's of all the properties where they have 'Wifi' and 'Close to pub'

so in this case i would like it to only return 1

Hope that i have made sence!

Upvotes: 0

Views: 58

Answers (2)

Andy Thompson
Andy Thompson

Reputation: 304

There are several ways to achieve this, one ugly way is:

select prop_id from features
   where name = 'Wifi' and prop_id in (
       select prop_id from features where name = 'Close to Pub'
       )

Upvotes: 1

slugonamission
slugonamission

Reputation: 9642

Use SELECT DISTINCT.

SELECT DISTINCT prop_id FROM table WHERE name="Wifi" or name="Close to pub"

Upvotes: 0

Related Questions