Union and NULL
I have noticed a strange behaviour when using union. Anyone who knows why this is happening? Is it a bug or a feature?
This is my problem when running the below queries separately without a union I get the following results:
+-----------+-------------+
| folder_id | folder_childid |
+-----------+-------------+
| 1 | 2 |
+-----------+-------------+
+-----------+-------------+
| folder_id | folder_childid |
+-----------+-------------+
| 2 | [NULL] |
| 3 | [NULL] |
+-----------+-------------+
The query:
SELECT folder_parentid AS folder_id, folder_id AS folder_childid
FROM folder
WHERE folder_parentid IS NOT NULL
UNION ALL
SELECT folder_id, null AS folder_childid
FROM folder
WHERE folder_parentid IS NULL
But when I use a UNION ALL on the queries, the NULLs are replaced by 0!
+-----------+-------------+
|__folder_id_|_folder_childid|
+-----------+-------------+
|______1_|________2_|
|______2_|________0_|
|______3_|________0_|
+-----------+-------------+
Why is this?
Subject
Written By
Posted
Union and NULL
August 10, 2004 03:26AM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.