【问题标题】:SQL Union : Selecting id of file_up tableSQL Union : 选择 file_up 表的 id
【发布时间】:2016-11-30 11:08:35
【问题描述】:

我有两个表 treeview_itemsfile_up

treeview_items

file_up

还有一个查询(不是我写的)

SELECT *
FROM treeview_items
UNION
    SELECT id + (select max(id) from treeview_items), name, 
          path as text,dir_id as parent_id
    FROM file_up

现在如何修改此查询,以便 file_up 表中的 id 也将列在查询结果中?我尝试了几件事,但仍然卡住了!

当前输出和预期输出,此处列名id from file_up仅用于演示。

【问题讨论】:

  • 你能显示你的预期输出吗
  • UNION 中的SELECT 语句必须具有相同的列数。您打算如何实现这一目标?
  • 预期输出还应包含 file_up 表的 id
  • 分享预期的输出。
  • 两个表的公共列是哪一列?

标签: mysql sql select union


【解决方案1】:

不确定我是否完全明白你在说什么,但你在寻找这样的东西吗?

SELECT *, WhateverID = NULL
FROM treeview_items
UNION
    SELECT id + (select max(id) from treeview_items), name, 
          path as text,dir_id as parent_id, WhateverID
    FROM file_up

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-22
    • 2019-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-10
    • 1970-01-01
    相关资源
    最近更新 更多