2016-11-30 83 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