If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > select distinct from two tables

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-13-04, 09:12
nglvert nglvert is offline
Registered User
 
Join Date: Jun 2004
Posts: 1
select distinct from two tables

I got two tables, table1 and table2:

table1
---------
country | code | something |
----------------------------
England | eng | cookie
USA | usa | banana
Italy | ita | frog
England | eng | green

table2
---------
country | code | somethang |
-----------------------------
Poland | pol | airplane
Canada | can | boat
England | eng | mule
Brazil | bra | owl

I'm trying to get it to return:

Brazil | bra
Canada | can
England | eng
Italy | ita
Poland | pol
USA | usa

I can't get it to work, i've tried all i can think of, so i'd really appreciate if someone could help me on this.

Thanks

Last edited by nglvert; 06-13-04 at 10:19.
Reply With Quote
  #2 (permalink)  
Old 06-20-04, 10:38
snorp snorp is offline
Registered User
 
Join Date: Apr 2004
Location: Europe->Sweden->Stockholm
Posts: 71
Quote:
Originally Posted by nglvert
I can't get it to work, i've tried all i can think of, so i'd really appreciate if someone could help me on this.
Thanks
I can't try this right now but shouldn't

(SELECT country,code FROM table1)
UNION DISTINCT
(SELECT country,code FROM table2)

work?
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On