Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Value before variable

I'm looking at some SQL code which has a WHERE clause like this:

WHERE 'USD' = CCY

I asked the writer why he's putting the value on the left hand side, and he said it's best practice to do so, stemming from C++ where people could mistakenly assign the value instead of comparing equality by forgetting the second equals sign.

I've never seen this before.

What are your thoughts?

like image 684
Nick Avatar asked Feb 05 '10 13:02

Nick


People also ask

What is & before a variable?

The & means "Don't take the variable, take the place in memory where this variable is stored." It's a little complicated, but it's necessary so that C can change the value of the variable.

What is before a variable in Java?

The plus(+) sign before the variables defines that the variable you are going to use is a number variable.

Why we use a in front of variables?

It passes a reference to the variable so when any variable assigned the reference is edited, the original variable is changed. They are really useful when making functions which update an existing variable.

What is before variable in PHP?

All variables in PHP start with a $ sign, followed by the name of the variable. A variable name must start with a letter or the underscore character _ . A variable name cannot start with a number. A variable name in PHP can only contain alpha-numeric characters and underscores ( A-z , 0-9 , and _ ).


1 Answers

Er, C++ is not SQL. There's no == in SQL and no assignments in a WHERE clause.

I'm not sure it qualifies as "best practice" but there is a convention which places the known value on the right-hand side. So, with a literal as in your example that would be

WHERE CCY = 'USD' 
like image 95
APC Avatar answered Oct 07 '22 00:10

APC