469,329 Members | 1,425 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,329 developers. It's quick & easy.

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 2473
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
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.