结果是两列 ( a_goods_name, b_goods_name ) 那不能用 union all
zbinlin
2022-05-21 12:04:05 +08:00
可以 join 两次表 B: SELECT B1.name AS a_goods_name, B2.name AS b_goods_name FROM A INNER JOIN goods AS B1 ON A.a_goods_id = B1.id INNER JOIN goods AS B2 ON A.b_goods_id = B2.id;
或者使用 subquery: SELECT (SELECT name FROM goods WHERE goods.id = A.a_goods_id) AS a_goods_name, (SELECT name FROM goods WHERE goods.id = A.b_goods_id) AS b_goods_name FROM A;
第 1 页 / 共 1 页
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。