Oracle SQL结果不一致

时间:2019-01-15 09:41:03

标签: sql oracle subquery

我有三个完全相同的sql查询。但是,其中之一不返回任何结果。我找不到适合该问题的解释。

任何人都可以

--returns one result
   SELECT col1
   FROM table1
   WHERE col1  not IN
   (select x.hesno from (SELECT c1||c2||c3 FROM Table2 S) x) ; 

--returns no result
   SELECT col1
   FROM table1
   WHERE col1  not IN
     (SELECT c1||c2||c3 FROM table2)  ;


--returns one result
   SELECT col1
   FROM Table1
   WHERE NOT EXISTS (
     SELECT 1 FROM table2 WHERE c1||c2||c3 = col1
   );

这是表格说明

Table1
Name   Null? Type          
------ ----- ------------- 
COL1          VARCHAR2(15)  

Table2
Name            Null? Type          
--------------- ----- ------------- 
C1                    VARCHAR2(2)   
C2                    VARCHAR2(3)   
C3                    VARCHAR2(10)

1 个答案:

答案 0 :(得分:3)

如果子查询在export default { data() { return { title: '', second_title: '' } }, mounted() { console.log('Component mounted.') }, methods: { addTask() { Event.$emit('taskCreated', { title: this.title, second_title: this.second_title }); axios.post('./api/word', { title: this.title, second_title: this.second_title, }) this.title = ''; this.second_title = ''; } 中返回空值,则查询将不返回任何行。

下面的SQL返回NOT IN ( subquery )

12345

With WTH0 AS (
  SELECT '12345' x FROM dual
),
WTH1 AS (
  SELECT '1' c1, '2' c2, '3' c3 FROM dual
)
SELECT X 
FROM WTH0
WHERE X NOT IN (SELECT C1||C2||C3 FROM WTH1);

返回空结果集。