CREATE TABLE EMPL_DEMO AS SELECT * FROM employees WHERE 1=2;
I read this statement somewhere on the internet but I couldn't understand the WHERE 1=2
.
Will anyone please, explain this?
The reason you put the WHERE 1=2 clause in that SELECT INTO query is to create a field-copy of the existing table with no data. If you did this: select * into Table2 from Table1. Table2 would be an exact duplicate of Table1 , including the data rows.
The SQL WHERE clause is used to specify a condition while fetching the data from a single table or by joining with multiple tables. If the given condition is satisfied, then only it returns a specific value from the table. You should use the WHERE clause to filter the records and fetching only the necessary records.
It means that MySQL has identified that it will result in zero rows.
A query like this can be used to ping the database. The clause: WHERE 1=0. Ensures that non data is sent back, so no CPU charge, no Network traffic or other resource consumption. A query like that can test for: server availability.
This type of command is usually used to copy the structure of one table to another. In this case, EMPL_DEMO
will have the same column structure of employees
, except for the keys or constraints.
The 1=2
always evaluates to False
which prevents you from copying any of the rows.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With