Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why we give in query sql 1=0

Tags:

mysql

I have seen in some programmers use 1=0 in where condition for select query , why they use this condition.

like image 468
XMen Avatar asked Dec 17 '10 17:12

XMen


2 Answers

in sql server, you can quickly create a copy of a table without any data like this

select * into Newtable
from Oldtable
where 1 = 0

this will create a new table with the same structure as the old table

Another option is to return an empty resultset

like image 132
SQLMenace Avatar answered Sep 23 '22 20:09

SQLMenace


The only possible use for that would be to prevent the query from returning any rows. I've done it occasionally for testing "no results found" type logic.

like image 26
ceejayoz Avatar answered Sep 22 '22 20:09

ceejayoz