2016-11-30 85 views
0

我有两个表treeview_itemsfile_upSQL联盟:file_up表中选择ID

treeview_items

img1

file_up

img2

和查询(不是我写的)

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 

现在,我怎么能修改此查询,以便IDfile_up表也将在查询结果中列出?我尝试了一些东西,但仍然卡住!

电流输出和预期输出,这里的列名来自file_up的ID仅供演示。

img3

+0

可以显示您的预期输出 – Chanukya

+1

UNION中的SELECT语句必须具有相同的列数。你打算如何实现这一目标? –

+0

预期输出还应包含file_up表的编号 –

回答

0

不知道如果我让你在说什么,但你在找这样的事情?

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