join three tables for specific result

后端 未结 2 1582
南方客
南方客 2021-01-27 14:49

I have three tables:

Table 1 Users:

+----------+------------+------------+-------------------+
| ID [PK]  |  username  |           


        
2条回答
  •  抹茶落季
    2021-01-27 15:39

    A LEFT JOIN will always return all records from the table on the left of the join, and only values from those records which match the join criteria from tables on the right of the join.

    To only return records for which there join criteria is validated for every record, you should use an INNER JOIN, i.e.:

    SELECT * 
    FROM 
        CR_AR C 
        INNER JOIN STRUCT S ON S.STRUCTURE = C.STRUCT 
        INNER JOIN USERS U ON U.USER_STRUCT = S.STRUCTURE
    

提交回复
热议问题