mysql - 多表连接查询的sql怎么写?
巴扎黑
巴扎黑 2017-04-17 11:49:11
0
3
452

有如下三张表:
user表:
ID 姓名 年龄
1 aaa 12
2 bbb 13
3 ccc 15
4 ddd 16

举报类型表
ID 类型
1 色情
2 诈骗

举报信息列表
ID 举报人ID 被举报人ID 举报类别ID
1 1 2 1
2 3 2 1
3 4 2 2

需查询:举报人姓名 被举报人姓名 举报类别

求教给位大神改怎么写sql!!

巴扎黑
巴扎黑

reply all(3)
洪涛

Suppose the three tables are tables A, B, and C;

Select a1.name, a2.name, b.type from A a1, A a2, B b, C c where a1.id=c.userId1 and a2.id=c.userId2 and b.id=c.typeId 
Peter_Zhu

Correct answer upstairs.
Provide another way of writing,
SELECT a1.name, a2.name, b.type FROM C c LEFT JOIN b c.typeId = b.id LEFT JOIN A a1 ON a1.id=c.userId1 LEFT JOIN A a2 ON a2.id=c.userId2;

Ty80

Several connections in SQL: inner join, left join, right join, full join, cross join: http://www.ido321.com/1061.html

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template