Help | Site Map
Connecting Tech Pros Worldwide
Reply
 
LinkBack Thread Tools
  #1  
Old August 13th, 2008, 10:16 AM
Newbie
 
Join Date: Aug 2008
Posts: 1
Default 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?
Reply
  #2  
Old August 13th, 2008, 03:05 PM
Administrator
 
Join Date: Sep 2006
Posts: 11,312
Default

From your table above, the country associated with parent 2 is TR only not TR and IR or am I missing something?
Reply
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles