2014-01-08 76 views
0

我需要對兩個複雜子查詢的結果進行聯合。我有以下查詢其在sqlite的在sqlite中使用複雜子程序的sql聯合查詢

select * from (select 
       objectid from osm where tag = 'b' 
        union 
       select 
       objectid from osm where tag = 'a'); 

我想修改它是如下工作(簡體):

select * from (select objectid from osm where tag = 'b' limit 10 
       union 
       select objectid from osm where tag = 'a' limit 10); 

這是不是在源碼有效。所以我試圖做的是

select * from 
    (select objectid from osm where tag = 'b' limit 10) as b, 
    (select objectid from osm where tag = 'a' limit 10) as a, 
    osm 
where 
    osm.objectid in (a union b); 

但這再次無效。我知道我可以做

osm.objectid in a OR osm.objectid in b; 

但由於某些技術原因我不能使用OR。有沒有辦法做到沒有OR?

回答

1

限制適用於整個查詢,所以你必須使用子查詢的一個單獨的層能夠聯盟有限公司查詢:

select * from 
    (select * from (select objectid from osm where tag = 'b' limit 10) 
    union 
    select * from (select objectid from osm where tag = 'a' limit 10)); 
0

這裏是我認爲可以讓你做你想做的一招:

select * 
from osm 
where objectid in (select objectid from osm where tab = 'b' limit 10) or 
     objectid in (select objectid from osm where tab = 'b' limit 10); 
+0

雖然它的工作原理,它使用一個OR,我不能使用 – iggy