MySQL Forums
Forum List  »  InnoDB

mysql INTERSECT equivalent
Posted by: Foad Shahla
Date: August 12, 2008 11:52AM

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?

Options: ReplyQuote


Subject
Views
Written By
Posted
mysql INTERSECT equivalent
10862
August 12, 2008 11:52AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.