Explanation for create table..
4 posters
Unix C++ :: UNIX CPP :: RDBMS & ORACLE
Page 1 of 1
Explanation for create table..
CREATE TABLE ord_sep AS SELECT * from ord_aug WHERE 1 = 2;
what does this 1=2 mean?? can nyone explain it, with an example..
what does this 1=2 mean?? can nyone explain it, with an example..
Preethi Sudhkar- Posts : 3
Points : 5
Join date : 2010-03-04
Re: Explanation for create table..
probably that table might contain a column named 1...with an entry 2
jeeva- Posts : 50
Points : 93
Join date : 2010-03-04
Re: Explanation for create table..
No i dont think so:)
Preethi Sudhkar- Posts : 3
Points : 5
Join date : 2010-03-04
Re: Explanation for create table..
i tried that n its creating a new table with the same column names without any entries as the condition doesn match any entry..
jeeva- Posts : 50
Points : 93
Join date : 2010-03-04
Re: Explanation for create table..
hmmm i dono the exact purpose of 1=2... an empty table with same columns is created even without that where clause...
jeeva- Posts : 50
Points : 93
Join date : 2010-03-04
Re: Explanation for create table..
Nothin its simple, whatever is there after where clause it takes it as a condition check. If that condition returns true then the statement before where will get excecuted...
try
sql> select * from <tablename> where 24=24;
It will check if 24 = 24 it will return true and the statement will be executed.
[edited]
Even if the condition is false the select statement is executed, displaying no rows selected...
try
sql> select * from <tablename> where 24=24;
It will check if 24 = 24 it will return true and the statement will be executed.
[edited]
Even if the condition is false the select statement is executed, displaying no rows selected...
Last edited by Mahee on Wed Mar 24, 2010 4:09 pm; edited 1 time in total
Mahee- Posts : 29
Points : 233
Join date : 2010-03-03
Location : Haldia
Re: Explanation for create table..
okie thanx
Preethi Sudhkar- Posts : 3
Points : 5
Join date : 2010-03-04
Re: Explanation for create table..
but 1=2 wont return true right!!!
jeeva- Posts : 50
Points : 93
Join date : 2010-03-04
Re: Explanation for create table..
Yes 1=2 is false.The table is created with the outline of the other table alone.
Eg : - CREATE TABLE ord_sep AS SELECT * from ord_aug WHERE 1 = 2;
will create a table ord_sep with the same fields as ord_aug.
But, CREATE TABLE ord_sep AS SELECT * from ord_aug will create ord_sep as an exact clone of ord_aug,i.e. not just the outline but the contents of ord_aug will be copied to ord_sep
Eg : - CREATE TABLE ord_sep AS SELECT * from ord_aug WHERE 1 = 2;
will create a table ord_sep with the same fields as ord_aug.
But, CREATE TABLE ord_sep AS SELECT * from ord_aug will create ord_sep as an exact clone of ord_aug,i.e. not just the outline but the contents of ord_aug will be copied to ord_sep
Maithreyi- Posts : 76
Points : 142
Join date : 2010-03-03
Age : 36
Location : Haldia
Re: Explanation for create table..
exactly,
whenever u execute,
sql> select * from <table> where <condition>
if condition return false, it doesnt mean that select statement is skipped. If Even the condition check return false, the select statement is executed displaying "no rows selected" as none of the tuples matches the criteria.
That is why no data is copied to the new table.
whereas while executing a command in which the condition check returns true and only the rows which satisfy the condition will be returned and those will be copied to the new table.
the condition 1=2 will be checked for each and every row of the table and no rows will be selected as that condition return false forever....
whenever u execute,
sql> select * from <table> where <condition>
if condition return false, it doesnt mean that select statement is skipped. If Even the condition check return false, the select statement is executed displaying "no rows selected" as none of the tuples matches the criteria.
That is why no data is copied to the new table.
whereas while executing a command in which the condition check returns true and only the rows which satisfy the condition will be returned and those will be copied to the new table.
the condition 1=2 will be checked for each and every row of the table and no rows will be selected as that condition return false forever....
Mahee- Posts : 29
Points : 233
Join date : 2010-03-03
Location : Haldia
Unix C++ :: UNIX CPP :: RDBMS & ORACLE
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum