List:General Discussion« Previous MessageNext Message »
From:Richard Lynch Date:April 25 2005 5:52am
Subject:Re: joining six tables by mutual column
View as plain text  
On Sun, April 24, 2005 3:51 pm, Schalk Neethling said:
> Hope someone can give me some pointers here. I have six tables in the
> database and I need to JOIN them on a row that appears in all of the
> tables. How do I do this? I have so far done the normal 'cross-join'
> saying SELECT * FROM table1, table2, table3, table4, table5, table6
> WHERE something = something;

SELECT *
FROM table1, table2, table3, table4, table5, table6
WHERE table1.something = table2.something
  AND table2.something = table3.something
  AND table3.something = table4.something
  AND table4.something = table5.something
  AND table5.something = table6.something

Make sure 'something' has an index on each table.

Also, don't use SELECT * unless you really NEED every column, and always
will, no matter how the schema changes.

If there's any chance at any time in the future that you won't need EVERY
column, then specify each and every column you need individually:

SELECT table1.something, table1.whatever, table2.something_else

-- 
Like Music?
http://l-i-e.com/artists.htm

Thread
joining six tables by mutual columnSchalk Neethling25 Apr
  • Re: joining six tables by mutual columnRichard Lynch25 Apr
  • RE: joining six tables by mutual columnmathias fatene25 Apr
    • Re: joining six tables by mutual columnSchalk Neethling2 May
      • Re: joining six tables by mutual columnPeter Brawley2 May
      • Re: joining six tables by mutual columnMichael Stassen2 May
  • Re: joining six tables by mutual columnNick Pasich25 Apr