I've got a user
table and a complaint
table.
The complaint
table has the following structure:
[opened_by] [complaint_text] [closed_by]
(user_id) (text) (user_id)
(user_id) (text) (user_id)
(user_id) (text) (user_id)
All users, both the complainers and complaint-resolvers are located in table user
.
How do I write a query to show the username for both columns?
This gives me one:
SELECT user.username, complaint.complaint_text
FROM complaint
LEFT JOIN user ON user.user_id=complaint.opened_by
but I don't know how to write it so both _by
columns show usernames rather than IDs.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…