tags:

views:

45

answers:

4

I have a very curious question. We have query to select records from table based on some condition. In general the syntax for the query is as below

SELECT * FROM TABLENAME WHERE COLUMNNAME='VALUE';

Now the question is that will this query will work if we interchange the position of COLUMNNAME and 'VALUE'.

+2  A: 

Yes. The following will work:

SELECT * FROM TABLENAME WHERE 'VALUE' = COLUMNNAME;
codaddict
+4  A: 

Yes, it will. =)

Why did you not just try?

Jens
+1  A: 

You mean

SELECT * FROM TABLENAME WHERE 'VALUE' = COLUMNNAME;

I tested it, it works on MSSQL Servver 2008

Tokk
I knew it works, but i am sure that most of the people are not aware of this.. so thought good way to make people aware of it. :)
Kamal
You are right, I would never have thought of it until I read your question ;)
Tokk
A: 

In fact, in Oracle at least, you can do some twisted but somewhat useful things like:

select *
from tablename
where 'VALUE' in (field1, field2, field3)
gpeche