joining the same table twice on different columns

后端 未结 4 1953

I\'ve got a user table and a complaint table.

The complaint table has the following structure:

[opened_by]   [         


        
4条回答
  •  爱一瞬间的悲伤
    2020-12-05 11:58

    SELECT user1.username AS opened_by_username, complaint.complaint_text, user2.username AS closed_by_username
    FROM user AS user1, complaint, user as user2
    WHERE user1.user_id = complaint.opened_by
    AND user2.user_id = complaint.closed_by
    

    Join it again using an alias (thats what the user as user2 stuff is about)

提交回复
热议问题