brb
brb

Reputation: 118

SQL: How do I read this?

I have this SQL instruction (given from someone else)

FROM P INNER JOIN
C ON P.p1 = C.p1 INNER JOIN
G INNER JOIN
U ON G.u1 = U.u1 ON
C.c1 = G.c1 INNER JOIN
R ON P.r1 = R.r1 INNER JOIN
F ON U.f1 = F.f1 RIGHT OUTER JOIN
UN ON U.u1 = UN.u1

How do I read all this? How do the 2nd, 3rd, 4th and 5th lines work?

Upvotes: 0

Views: 62

Answers (1)

Paddy
Paddy

Reputation: 33857

With some formatting, I think it becomes easier:

FROM P INNER JOIN C 
   ON P.p1 = C.p1 
INNER JOIN G 
INNER JOIN U 
   ON G.u1 = U.u1 
   ON C.c1 = G.c1 
INNER JOIN R 
   ON P.r1 = R.r1 
INNER JOIN F 
   ON U.f1 = F.f1 
RIGHT OUTER JOIN UN 
    ON U.u1 = UN.u1

And then it looks like one of your ON's is in the wrong place:

FROM P INNER JOIN C 
   ON P.p1 = C.p1 
INNER JOIN G 
   **ON C.c1 = G.c1**       
INNER JOIN U        
    ON G.u1 = U.u1
INNER JOIN R 
   ON P.r1 = R.r1 
INNER JOIN F 
   ON U.f1 = F.f1 
RIGHT OUTER JOIN UN 
    ON U.u1 = UN.u1

Formatting really helps this sort of thing...

Upvotes: 3

Related Questions