Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Single Equals in MYSQL

I was wondering why MYSQL uses a single equals sign in conditional statements instead of the more typical two equals signs. Is there a technical/historical reason for this? Thanks.

like image 558
Anon Avatar asked Jul 15 '09 17:07

Anon


People also ask

Can you use == in SQL?

SQL is a declarative language, and assignments are not typically made in SQL queries themselves. As a result, SQL doesn't have the problem of ambiguity of = meaning either assignment or equality check. As a result, there is no problem with using = to check equality.

How do I check for equal conditions in MySQL?

In MySQL, you can use the = operator to test for equality in a query. The = operator can only test equality with values that are not NULL. For example: SELECT * FROM contacts WHERE last_name = 'Johnson';

Does SQL use double equals?

There is no double equal sign concept. It can be used to compare two values. If you use double equal sign(==) in MySQL, you will get an error message.


2 Answers

Hi, I was wondering why MYSQL uses a single equals sign in conditional statements instead of the more typical two equals signs. Is there a technical/historical reason for this? Thanks.

Comparison is much more common in SQL than assignment.

That's why SQL uses more short syntax to do more common things.

In classical SQL, comparison can be distinguished from assignment by context (assignment can be only in SET clause of an UPDATE statement), that's why one operator can be used for both operations.

In MySQL's extension to SQL, assignment to a session variable is denoted by :=

like image 65
Quassnoi Avatar answered Sep 28 '22 04:09

Quassnoi


More like historical.

It's SQL. It has used a single equals sign for comparison since the early '70s.

like image 34
Guffa Avatar answered Sep 28 '22 04:09

Guffa