从表中选择非唯一字段,其中数据不包含字符串

时间:2013-02-14 16:07:01

标签: sql oracle select

首先,这就是表格的样子:

Checkpoint
==========
trans_id
checkpoint_id

Checkpoint_Data
===============
checkpoint_id
data

trans_id并非checkpoint唯一。 checkpoint_idcheckpoint以及checkpoint_data都是唯一的。 Checkpoint_id链接checkpointcheckpoint_data

我想从trans_id中选择来自checkpoint的关联data不包含某些字符串的所有checkpoint_data

我基本上想要反驳这句话:

SELECT ch.trans_id
FROM   checkpoint ch,
       checkpoint_data chd
WHERE  ch.checkpoint_id = chd.checkpoint_id
     AND Upper(chd.data)LIKE Upper('%Example String%')

一个简单的不喜欢不起作用。

2 个答案:

答案 0 :(得分:1)

或类似的东西......

SELECT ch.trans_id
FROM   checkpoint ch
except
SELECT ch.trans_id
FROM   checkpoint ch,
   checkpoint_data chd
WHERE  ch.checkpoint_id = chd.checkpoint_id
 AND Upper(chd.data)LIKE Upper('%Example String%')

答案 1 :(得分:0)

这样的事情?

SELECT ch.trans_id
FROM   checkpoint ch
WHERE not exists ( select * from checkpoint_data chd
                   where ch.checkpoint_id = chd.checkpoint_id 
                   AND Upper(chd.data) LIKE Upper('%Example String%')
                  )