2

Is it possible to do the following join?

Select *
From table1
Inner join table2 on table1.pk = table2.fk
Inner join table3 on table2.pk = table3.fk and table1.pk = table3.fk

Normally I have only use two tables in one join statement. The last statement has three tables.

Giorgi Nakeuri
  • 35,155
  • 8
  • 47
  • 75
Sheng Liu
  • 79
  • 1
  • 8

1 Answers1

3

Just do:

SELECT *
FROM table1
INNER JOIN table2 
   ON table1.pk = table2.fk
INNER JOIN table3 
   ON table1.pk = table3.fk
   AND table2.pk = table3.fk

Side note

In theory you can join to as many tables as you like - just be aware that the more tables you join to, the more the performance will be impacted negatively.

At that point it's better to think carefully about the query you are constructing and consider breaking it down into smaller queries as these will be more efficient.

Ilessa
  • 602
  • 8
  • 27