2016-11-30 91 views
0

SQL新手在這裏。在多個表中選擇同一列的差異sql

我有這樣的模式:

where nodes table and ways table have the same column uid

我需要用簡單的英語是什麼:

「出了2列,使一個在另一個的上面一個欄,再算上多少distincts值有」

我已經試過

SELECT COUNT (DISTINCT uid) from nodes UNION SELECT COUNT (DISTINCT uid) from ways ; 

SELECT distinct nodes.uid from nodes JOIN ways on nodes.uid = ways.uid ; 

sqlite> SELECT COUNT (DISTINCT uid) from nodes UNION SELECT COUNT (DISTINCT uid) from ways ; 
1195 
2182 
sqlite> SELECT uid from nodes FULL OUTER JOIN ways on nodes.uid = ways.iud ; 
Error: RIGHT and FULL OUTER JOINs are not currently supported 

SELECT COUNT (DISTINCT iud) FROM (SELECT DISTINCT uid from nodes as uid UNION SELECT DISTINCT uid from ways as uid as subq); 

SELECT count (distinct nodes.uid) from nodes JOIN ways on nodes.uid = ways.uid ; 

需要年齡和我不知道nodes.uid = ways.uid是去

任何想法的正確方法是什麼?

回答

0

我覺得我得到它

SELECT COUNT (DISTINCT uid) from (SELECT DISTINCT uid from nodes UNION SELECT DISTINCT uid from ways) as subq ; 
0

自聯盟返回一組不同的你不需要使用DISTINCT關鍵字

SELECT COUNT(uid) Cnt 
FROM (
    SELECT uid 
    FROM nodes 
    UNION 
    SELECT uid 
    FROM ways 
) t 
的連接表
相關問題