Hi All,
I am trying to execute this kind of query that uses'Not in ' function but unable to get 'Nulls'
select * from table1 where col1 not in (select col2 from table2).
Here col1 is not primary key in table1 and col2 is not foreign key for col1. They store same kind of data.
There are few nulls for col1 in table 1 and no nulls for col2.
If i execute the above statement , the rows with nulls for col1 are not retrieving.
As these nulls are not in col2 of table2, they should be retrieved right?
1 1446
Hi,
NULL is considered "UNKNOWN". It is never "IN" or "NOT IN" anything. If you want to see the rows where COL1 is NULL, you have to do so explicitly using the "IS NULL" clause in your query.
Example: - chris@XE> DROP TABLE t1;
-
-
Table dropped.
-
-
Elapsed: 00:00:00.03
-
chris@XE>
-
chris@XE> CREATE TABLE t1 (
-
2 ID NUMBER(10),
-
3 col1 VARCHAR2(1)
-
4 );
-
-
Table created.
-
-
Elapsed: 00:00:00.00
-
chris@XE>
-
chris@XE> INSERT INTO t1
-
2 VALUES (1, 'a');
-
-
1 row created.
-
-
Elapsed: 00:00:00.01
-
chris@XE> INSERT INTO t1
-
2 VALUES (2, 'b');
-
-
1 row created.
-
-
Elapsed: 00:00:00.00
-
chris@XE> INSERT INTO t1
-
2 VALUES (3, 'c');
-
-
1 row created.
-
-
Elapsed: 00:00:00.01
-
chris@XE> INSERT INTO t1
-
2 VALUES (4, 'd');
-
-
1 row created.
-
-
Elapsed: 00:00:00.00
-
chris@XE> INSERT INTO t1
-
2 VALUES (5, NULL);
-
-
1 row created.
-
-
Elapsed: 00:00:00.00
-
chris@XE> INSERT INTO t1
-
2 VALUES (6, 'e');
-
-
1 row created.
-
-
Elapsed: 00:00:00.03
-
chris@XE> INSERT INTO t1
-
2 VALUES (7, 'f');
-
-
1 row created.
-
-
Elapsed: 00:00:00.03
-
chris@XE> INSERT INTO t1
-
2 VALUES (8, NULL);
-
-
1 row created.
-
-
Elapsed: 00:00:00.01
-
chris@XE> INSERT INTO t1
-
2 VALUES (9, 'g');
-
-
1 row created.
-
-
Elapsed: 00:00:00.01
-
chris@XE>
-
chris@XE> COMMIT ;
-
-
Commit complete.
-
-
Elapsed: 00:00:00.01
-
chris@XE>
-
chris@XE> DROP TABLE t2;
-
-
Table dropped.
-
-
Elapsed: 00:00:00.06
-
chris@XE>
-
chris@XE> CREATE TABLE t2 (
-
2 ID NUMBER(10),
-
3 col2 VARCHAR2(1) NOT NULL
-
4 );
-
-
Table created.
-
-
Elapsed: 00:00:00.03
-
chris@XE>
-
chris@XE> INSERT INTO t2
-
2 VALUES (1, 'a');
-
-
1 row created.
-
-
Elapsed: 00:00:00.03
-
chris@XE> INSERT INTO t2
-
2 VALUES (3, 'c');
-
-
1 row created.
-
-
Elapsed: 00:00:00.03
-
chris@XE> INSERT INTO t2
-
2 VALUES (7, 'f');
-
-
1 row created.
-
-
Elapsed: 00:00:00.01
-
chris@XE>
-
chris@XE> COMMIT ;
-
-
Commit complete.
-
-
Elapsed: 00:00:00.01
-
chris@XE>
-
chris@XE> SELECT *
-
2 FROM t1
-
3 WHERE col1 NOT IN (SELECT col2
-
4 FROM t2);
-
-
ID C
-
---------- -
-
2 b
-
4 d
-
6 e
-
9 g
-
-
Elapsed: 00:00:00.06
-
chris@XE>
-
chris@XE>
-
chris@XE> SELECT *
-
2 FROM t1
-
3 WHERE col1 NOT IN (SELECT col2
-
4 FROM t2)
-
5 OR col1 IS NULL;
-
-
ID C
-
---------- -
-
2 b
-
4 d
-
5
-
6 e
-
8
-
9 g
-
-
6 rows selected.
-
-
Elapsed: 00:00:00.07
-
chris@XE>
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Penn Markham |
last post by:
Hello all,
I am writing a script where I need to use the system() function to call
htpasswd. I can do this just fine on the command line...works great
(see attached file, test.php). When my...
|
by: John Collyer |
last post by:
Hi,
In assembly language you can use a lookup table to call functions.
1. Lookup function address in table
2. Call the function
Like:
CALL FUNCTION
|
by: bluedolphin |
last post by:
This is my first function in Visual and I'm having a simple syntax
syntax issue that I'm hoping someone can help correct for me.
I have a function
Public Function...
|
by: Stuart McGraw |
last post by:
I am looking for a VBA "format" or "template" function, that is,
a function that takes a format string and a varying number of
arguments, and substitutes the argument values into the format
string...
|
by: Cancerbero |
last post by:
Hi (first, excuse me for my bad english)
As I know, the semantics for typedef is:
typedef A B;
I think this makes B a synonym of A, where A is an existing data type. Is
that right?
Based...
|
by: Dmitry Anikin |
last post by:
I mean, it's very convenient when default parameters
can be in any position, like
def a_func(x = 2, y = 1, z):
...
(that defaults must go last is really a C++ quirk which
is needed for overload...
|
by: Csaba Gabor |
last post by:
I feel like it's the twilight zone here as several seemingly trivial
questions are bugging me.
The first of the following three lines is a syntax error, while the
last one is the only one that...
|
by: I.M. !Knuth |
last post by:
Hi. I'm more-or-less a C newbie. I thought I had pointers under control until
I started goofing around with this:
...
|
by: Tony Lownds |
last post by:
(Note: PEPs in the 3xxx number range are intended for Python 3000)
PEP: 3107
Title: Function Annotations
Version: $Revision: 53169 $
Last-Modified: $Date: 2006-12-27 20:59:16 -0800 (Wed, 27 Dec...
|
by: Angus |
last post by:
Hello
I am writing a library which will write data to a user defined callback
function. The function the user of my library will supply is:
int (*callbackfunction)(const char*);
In my...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |