Posted By

Scooter on 11/10/08



Versions (?)

Joining the same table on different columns

 / Published in: SQL

I had a situation recently where I needed to join the same table on different columns. Most web sites don't give an example of this, so I thought it a good idea to post here. The example below only shows joining twice, but you can join as many times as necessary.

  1. SELECT column1, table2.COLUMN AS column2, table3.COLUMN AS column3
  2. FROM table1
  3. JOIN otherTable AS table2 ON table1.FK1 = table2.PK
  4. JOIN otherTable AS table3 ON table1.FK2 = table3.PK
  5. WHERE table1.PK = ?

Report this snippet  

You need to login to post a comment.