2014-03-12 72 views
0

我正在使用CQL的OCEP平臺上開發。CQL替換爲「不在」子查詢

我正在尋找一種方法來從一個表中選擇不存在於另一個表中的值。 CQL不允許使用子查詢,所以我不能簡單地使用「不在(查詢)」。

尋找這個替代:

select * 
from tb1 
where tb1.id not in (select id from tb2) 

表1:1,3,4,5,6。 表2:1,4,7,9。

我正在尋找一種方法來獲取(3,5,6)作爲值的表。

任何想法將受到歡迎:)

回答

1

這也可以使用外部進行連接:

select one_table.* 
from one_table 
    left join another on one_table.pk_column = another.fk_column 
where another.pk_column is null; 

你的榜樣,然後映射到該查詢:

select tb1.* 
from tb1 
    left join tb2 on tb1.id = tb2.id 
where tb2.id is null; 

SQLFiddle例如: http://sqlfiddle.com/#!4/4594f/2

+0

不幸的是,這不是我正在尋找的。 我會編輯我的帖子,並嘗試更好地解釋它。 –

+0

@AlexeiBabin:那正是你正在尋找的。 –