![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I am reading FUNDAMENTALS OF DATABASE SYSTEMS where it says "In general, a query written with nested SELECT...FROM...WHERE... blocks and using = or IN comparison operators can always be expressed as a single block query." I believe this is true. Now I wonder whether similar structure with 'NOT IN' comparison operator can be expressed as a single block query. Can any body give me an example? I couldn't understand completely of your statements. |
#3
| |||
| |||
|
#4
| |||
| |||
|
|
I made mistake. For NOT IN case: SELECT col_a, col_b, ... FROM (SELECT expression_a1, expression_a2, ... FROM <table-reference-a WHERE condition_a) S(col_a, col_b, ...) WHERE col_a NOT IN (SELECT expression_b FROM <table-reference-b WHERE condition_b); Rewrited Query should be: SELECT expression_a1 AS col_a, expression_a2 AS col_b, ... FROM <table-reference-a LEFT OUTER JOIN table-reference-b ON condition_b AND expression_a1 = expression_b WHERE condition_a AND expression_b IS NULL; |
![]() |
| Thread Tools | |
| Display Modes | |
| |