MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMySQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old February 14th, 2000, 09:50 AM
Marc Boon Marc Boon is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2000
Posts: 4 Marc Boon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
How to get all unique (distinct) rows from more than one table, having at least one equal column name?
For example: table1 and table2 have same columns, table1 has 10 rows, table2 has 20 rows. 5 of them also exist in table1, but i want the 35 distinct rows from both tables combined.

Reply With Quote
  #2  
Old February 15th, 2000, 02:41 AM
PAV PAV is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 1999
Location: Netherlands
Posts: 77 PAV User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
Hi Marc,

What you want is a "difference" query between both tables, in which you get the 15 unique rows?
I assume you set up both tables with an unique ID column. Now to get the 15 non-overlapping rows from both tables, do:

select * from Table1 t1, Table2 t2 where t1.ID <> t2.ID

Peter


Reply With Quote
  #3  
Old February 15th, 2000, 03:04 AM
Marc Boon Marc Boon is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2000
Posts: 4 Marc Boon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Well, no, this is not what I meant.
I do have unique id's in both table's, but both table's also contain an email field.
What I want is al rows from both tables with distinct emails (no duplicates). There may be duplicate id's, since the tables are unrelated. Actually I need to 'virtually' concatenate the tables and then select the distinct emails.
How do I do this?

Reply With Quote
  #4  
Old February 15th, 2000, 08:44 AM
Marc Boon Marc Boon is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2000
Posts: 4 Marc Boon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Found it!
I just bought the book "MySQL" by Paul DuBois (New Riders,ISBN 0-7357-0921-1) and there it was: under the heading "Solutions Miscellany" (p. 167) I read that what I need was a UNION, but mySQL doesn't support that.
The workaround is to create a temporary table and insert records into it from my tables. Then do a select on the temporary table and drop it when finished.
Thanks Paul!

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > joining similar tables


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway