mysql - SQL 3 column query on condition -


i'm still pretty new sql , have table following

street     |  family  |  car -------------------------------- mayfair    |  jones   |  bmw mayfair    |  jones   |  ford mayfair    |  jones   |  mazda mayfair    |  smith   |  bmw mayfair    |  fox     |  bmw park lane  |  taylor  |  ford park lane  |  taylor  |  mazda park lane  |  cole    |  bmw 

i wondering if there single query can done check particular street, see if there car family's have?

so instance in above table query return bmw mayfair family's on mayfair own bmw.

i'm using xampp @ moment mysql don't have fancy server or setup etc...

thanks

select street, car  tablex t1 group street, car having count(distinct family)        = ( select count(distinct t2.family)            tablex t2            t2.street = t1.street          ) 

or:

select distinct street, car               --- show streets , cars tablex  not exists                          --- there no   ( select family                         --- family     tablex f     f.street = a.street             --- in street       , not exists                      --- hasn't         ( select car           tablex c           c.family = f.family                   , c.car = a.car             --- car         )   ) 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -