4

我有大约 10 个表,所有表的列数各不相同,但都包含列“client_id”,这是将每个表中的所有记录链接在一起的关键。

我想抓取所有表中的所有列。

在 client_id 上将所有 10 个左右的表连接在一起的最佳方法是什么?

想要这样做的原因是因为我想将所有表导出到 1 个单个 CSV 文件中。

4

2 回答 2

4

从包含所有客户端 ID 的表开始,并使用USING关键字左连接剩余的表:

 SELECT *
 FROM table1
 LEFT JOIN table2 USING (client_id)
 LEFT JOIN table3 USING (client_id)
 LEFT JOIN table4 USING (client_id)
 ...
于 2012-11-28T08:35:32.357 回答
0
select *
from table1 t1,
table2 t2,
table3 t3...
where t1.user_id=t2.user_id
and t1.user_id=t3.user_id...
于 2012-11-28T08:35:14.450 回答