数据库;一列中的不同 ID?

标签 mysql sql

非常感谢任何帮助。

我现在正在使用这个查询。

SELECT t.itemID, RepID, InsRepairID
    FROM tbl_item t
        left join tbl_insiderepair i on i.itemID = t.itemID
        left join tbl_underrepair u on u.itemID = t.itemID
    where(i.itemID = t.itemID Or u.itemID = t.itemID);

这是结果。

itemID     |     RepID     |     InsRepairID
1                       3                     null
2                      null                    1
3                      null                    2

现在我想将“RepID 和 InsRepairID 列”(它们是来自不同表的 ID)变成一个列。

最佳答案

通过使用 Union,您可以在一列中添加两个表

Select  itemID, RepID from  tbl_item
union
SELECT   itemID,InsRepairID from tbl_insiderepair

关于数据库;一列中的不同 ID?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32622331/

相关文章:

mysql - 在 MySQL 中存储 IPv6 地址

PHP获取MySQL记录时出现 undefined variable 错误

php mysql - 尝试为用户发布的频率添加时间限制

sql - 仅获取属性的默认图像

mysql - 为什么 MySQL Workbench 在创建表之间的关系时会自动创建多个键?

mysql - 如何使所有数据库记录都以特定值开头?

sql - 结合 2 个复杂的查询

mysql - 错误 : column is invalid because it is not contained in either an aggregate function or the GROUP BY

mysql - phpmyadmin 不会导入 funstuff.sql.zip 文件

mysql - 如何设计具有撤消重做功能的 SQL 数据库?