Multiple Table Join in MySQL




Normal SQL Format
-----------------------------

SELECT A.<column_name> AS FIRSTNAME,B.<column_name> AS LASTNAME,C.<column_name> AS JOB 
FROM A,B,C
WHERE
 
A.ID = B.ID AND
B.ID = C.ID


ANSI Format
-------------------
SELECT A.<column_name>,B.<column_name>,C.<column_name> 
FROM A INNER JOIN B
 
ON
 A.ID = B.ID INNER JOIN C
ON
 B.ID = C.ID


Also
SELECT A.<column_name> AS FIRSTNAME,B.<column_name> AS LASTNAME,C.<column_name> AS JOB 
FROM A,B,C
WHERE
 
A.ID = B.ID AND
B.ID = C.ID AND (any other filter Condition ,such as A.status = 'TRUE')
ORDER BY A.<column_name>,B.<column_name>


SELECT A.<column_name>,B.<column_name>,C.<column_name> 
FROM A INNER JOIN B
 
ON
 A.ID = B.ID INNER JOIN C
ON
 B.ID = C.ID AND (any other filter Condition ,such as A.status = 'TRUE')
ORDER BY A.<column_name>
 
eg :
SELECT UPPER (U.USER_NAME) USERNAME, REPLACE(UR.USER_ROLE,'_') ROLE,L.NAME ACTION FROM LIMSCOTTON.LIMS_USERS U,LIMSCOTTON.USER_ROLE UR,LIMSCOTTON.GROUP_ENTRY L WHERE  UPPER (TRIM(U.USER_NAME)) = UPPER (TRIM(UR.USER_NAME)) AND UPPER (TRIM(UR.USER_NAME)) = UPPER(TRIM(L.USER_NAME)) AND UPPER (TRIM(U.USER_DISABLED)) = 'F' ORDER BY UPPER (U.USER_NAME)