【发布时间】:2014-07-09 15:33:03
【问题描述】:
我有以下表格,
从 tbl1 中选择 *;
+------+------------+---------+----------+
| id | userId | part_id | url |
+------+------------+---------+----------+
| 1 | 155 | 1 | "http:/" |
+------+------------+---------+----------+
从 tbl2 中选择 *;
+------+------------+---------+-------------+------------+-----------+
| id | userId | part_id | tbl2_id1 | tbl2_id2 | notes |
+------+------------+---------+-------------+------------+-----------+
| 1 | 155 | 1 | 12 | 1 | note 1 |
| 2 | 155 | 1 | 12 | 2 | note 2 |
+------+------------+---------+-------------+------------+-----------+
如您所见,tbl2 有两个 FK(userId 和 part_id),tbl2_id1 和 tbl2_id2 是 tbl2 的 PK。
我的问题是如何在一个查询中从两个表中获取三条记录?
像这样的
1 | 155 | 1 |"http:/" | from tbl1
1 | 155 | 1 | note 1 | from tbl2
2 | 155 | 1 | note 2 | from tbl2
【问题讨论】: