View Single Post
  #1 (permalink)  
Old October 21st, 2004, 05:50 PM
dcb22 dcb22 is offline
Registered User
 
Join Date: Oct 2004
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Mysql Sorting results from multiple tables

I'm really struggling to get my head around joins and was wondering if someone could point me in the right direction. I have 1 table that has a primary key and then maybe 2 or 3 other tables that have a foreign key.

The tables with the foreign key are identical (currently) and basically I want to do a select that gets all the data from the 3 foreign tables, does a WHERE to only get the records after the present time (from a field containing the date) and then does a sort on that time field so we can take the 5 records with entries nearest to the future.

So for example maybe it's like...

TABLE A
my_primary_key

TABLE B
my_foreign_key
my_date

TABLE C
my_foreign_key
my_date

TABLE D
my_foreign_key
my_date

I've looked at UNION which forces the data into one table but then I can't do the WHERE things I want to do. I tried Joins but I couldn't figure how to join the tables together. If anyone's a SQL buff and can help me out quickly I'd be most greatful,

cheers,

Dave