472,145 Members | 1,538 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,145 software developers and data experts.

mysql INTERSECT equivalent

Hi all,

I have the table below.

+--------+---------+-------------+--------------------------------+-------+----+

| parent | country | city | hotel | stars | id |

+--------+---------+-------------+--------------------------------+-------+----+

| 1 | AE | Dubai | Emirates Towers | 5 | 1 |

| 1 | AE | Khor Fakkan | Le Meridien Al Aqa Beach Resor | 5 | 2 |

| 2 | TR | Antalya | Rixos | 5 | 3 |

| 2 | IR | Tehran | Esteghlal | 5 | 4 |

| 3 | TR | Antalya | Laress Park | 5 | 5 |

+--------+---------+-------------+--------------------------------+-------+----+

I want to query the db such that it selects all parents whose associated countries are TR AND IR. in other words I want to find the parent(s) that necessarily include both TR and IR. in this example the result would be 2 since
parents 1 and 3 do not include both TR AND IR.

using INTERSECT:
i think this can be done easily using INTERSECT(havent tried it thouh)
select parent from destinations where country='IR'
INTERSECT
select parent from destinations where country='TR';

any ideas as to whats the equivalent for the above query in mysql?
Aug 13 '08 #1
1 2589
r035198x
13,262 8TB
From your table above, the country associated with parent 2 is TR only not TR and IR or am I missing something?
Aug 13 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

6 posts views Thread by Nick | last post: by
5 posts views Thread by Jandre | last post: by
3 posts views Thread by prathamesh.deshpande | last post: by
1 post views Thread by kadhir34 | last post: by
reply views Thread by Saiars | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.