SELECT * FROM Table JOIN Other ON Table.id = Other.tableId
I’m structuring a MySQL wrapper, and wondering if the “ON” keyword is used only in conjunction with joins (like above), or somewhere else as well?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The
ONkeyword is also found and can be in several other places, likeCREATE TABLEandALTER TABLEtable statements (in theFOREIGN KEYdefinitions:ON DELETE CASCADE), in theCREATE TRIGGERsyntax (ON tbl_name FOR EACH ROW), in theCREATE INDEXstatements, etc.For joins, the
JOINsyntax in the MySQL documentation has it all:So,
ONcan be used inSELECT,UPDATEandDELETEstatements. It can be used withJOIN,LEFT JOIN,RIGHT JOIN(and the equivalentINNER JOIN,LEFT OUTER JOIN,RIGHT OUTER JOIN).Either
ONorUSINGis to be used, not both.It cannot be used with
NATURAL JOIN(of course.)And some differences from the ANSI/ISO SQL standard:
you can use
ONwithCROSS JOIN.also (optionally) with
STRAIGHT_JOIN(that’s a MySQL addition)you can use
JOINandINNER JOINwithoutON.UPDATEandDELETEsyntax has some differences with the standard, too.