Mysql查询5张表

发布于 2024-12-01 15:32:09 字数 462 浏览 0 评论 0原文

我在谷歌上搜索了两个小时,但没有找到我认为简单的东西。我有 4 个表,我可以将下面的前 4 个表合并在一起,并且我拥有所有表中的所有行。我试图弄清楚如何添加 1 个额外的 FullName 列,以便所有结果在基于 b 的每一行中显示 table5 中的 FullName,而 b 位于所有其他表中。我希望这对某人有意义。

SELECT  a, b, NULL AS Name FROM table1
union SELECT a, b, NULL AS Name FROM table2
 union SELECT a, b, NULL AS Name FROM table3
 union SELECT a, b, NULL AS Name FROM table4
union SELECT NULL AS a, b, FullName  FROM table5 where

.....b 等于前面 4 个 select 语句中的任意 b

I have searched google for 2 hours and no luck on what I think is simple. I have 4 tables that I can union together the first 4 below and I have all the rows from all the tables. I am trying to figure out how I can add 1 extra column of FullName so that all the results show the FullName from table5 in every row based on b which is in all the other tables. I hope this makes sense to someone.

SELECT  a, b, NULL AS Name FROM table1
union SELECT a, b, NULL AS Name FROM table2
 union SELECT a, b, NULL AS Name FROM table3
 union SELECT a, b, NULL AS Name FROM table4
union SELECT NULL AS a, b, FullName  FROM table5 where

.....b is equal to any b in the previous 4 select statements

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

挽袖吟 2024-12-08 15:32:09
SELECT unions.*, tb5.FullName
FROM (
SELECT a, b FROM table1
union SELECT a, b FROM table2
union SELECT a, b FROM table3
union SELECT a, b FROM table4
union SELECT a, b FROM table5
) AS unions
JOIN table5 AS tb5 ON unions.b = tb5.b

可能有用吗?

编辑:更新...

SELECT unions.*, tb5.FullName
FROM (
SELECT a, b FROM table1
union SELECT a, b FROM table2
union SELECT a, b FROM table3
union SELECT a, b FROM table4
union SELECT a, b FROM table5
) AS unions
JOIN table5 AS tb5 ON unions.b = tb5.b

Might work?

EDIT: Updated...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文