Wouter Wouter - 6 months ago 19
SQL Question

SQL get information from 4 tables

I have a database from which I need to

JOIN
4 tables and I am having some trouble figuring it out

I have the following tables

A. id, name, picture, d_id
B. id, name
C. id, a_id, b_id, commentaar
D. id, name


Does anyone have any idea how to go about this?
A
has data used in
D
and
C
has data used in
A
and
B
, so I am at a loss how to get this one done. I want to output

A.name, A.picture, B.Name, C.commentaar, D.name

Answer

Unless I'm missing something, you just need to do this:

Select  A.name, A.picture, B.Name, C.commentaar, D.name
From    A
Join    D   On  A.d_id = D.id
Join    C   On  C.a_id = A.id
Join    B   On  C.b_id = B.id