Precautions for using LEFT JOIN

Today I wrote sql using associations, left join started, and the result... an error was reported

Click on sql, (replace the elements inside, so you can understand it)

		
 SELECT 
    A.aid
    B.bname
    C.csex
	D.dname
    E.ename
    F.fname
FROM 
    Admin A,
    Boy B,
    Classmate C
        
	LEFT JOIN Dog D 
	ON 
	(C.cid = D.did)
	LEFT JOIN (
	   SELECT eid,ename FROM Element
	) E
	ON(
	    C.cid = E.eid
	)
	LEFT JOIN Friend F
    ON(
        A.aid = F.fid 
    )

Let's take a look at the error message

1) [Code: -338, SQL State: 42972]  An ON clause associated with a JOIN operator or in a MERGE statement is not valid.. SQLCODE=-338, SQLSTATE=42972, DRIVER=4.22.29
2) [Code: -727, SQL State: 56098]  An error occurred during implicit system action type "2". Information returned for the error includes SQLCODE "-338", SQLSTATE "42972" and message tokens "42972".. SQLCODE=-727, SQLSTATE=56098, DRIVER=4.22.29

Well, this error means that the ON clause associated with the JOIN operator or MERGE statement is invalid. There is a problem with ON.

[Reason] The left join follows a table, which means that only the elements of the next table can be called in on. Here, in the last left join, the elements of table A are called in on, which is wrong.

[Correction]

		
 SELECT 
    A.aid
    B.bname
    C.csex
	D.dname
    E.ename
    F.fname
FROM 
    Admin A 
    LEFT JOIN Friend F
    ON(
        A.aid = F.fid 
    ),
    Boy B,
    Classmate C   
	LEFT JOIN Dog D 
	ON 
	(C.cid = D.did)
	LEFT JOIN (
	   SELECT eid,ename FROM Element
	) E
	ON(
	    C.cid = E.eid
	)
	

Ok, I’m here today, I hope I won’t work overtime for 520 next year

Guess you like

Origin blog.csdn.net/qq_36766417/article/details/106243265