w3resource

MySQL equal operator

equal operator

MySQL equal operator performs an equality comparison.

Syntax:

=

MySQL Version: 8.0

Example: MySQL equal operator

The following MySQL statement checks if 1 is equal to 1, if 1 is equal to 2, if NULL is equal to NULL, if NULL is equal to 3 and if 3 is equal to NULL.

Code:

SELECT 1 = 1, 1=2,NULL = NULL, NULL=3,3= NULL;

Output:

mysql> SELECT 1 = 1, 1=2,NULL = NULL, NULL=3,3= NULL;
+-------+-----+-------------+--------+---------+
| 1 = 1 | 1=2 | NULL = NULL | NULL=3 | 3= NULL |
+-------+-----+-------------+--------+---------+
|     1 |   0 |        NULL |   NULL |    NULL | 
+-------+-----+-------------+--------+---------+
1 row in set (0.00 sec)

Example: MySQL equal operator with WHERE clause

The following MySQL statement will fetch the rows after checking whether the publisher belongs to the USA.

Code:

SELECT pub_name,country,pub_city,estd
FROM publisher           
WHERE country='USA';

Relational Algebra Expression:

Relational Algebra Expression: MySQL equal operator with WHERE clause.

Relational Algebra Tree:

Relational Algebra Tree: MySQL equal operator with WHERE clause.

Sample table: publisher


Output:

mysql> SELECT pub_name,country,pub_city,estd
    -> FROM publisher           
    -> WHERE country='USA';
+--------------------------+---------+----------+------------+
| pub_name                 | country | pub_city | estd       |
+--------------------------+---------+----------+------------+
| Jex Max Publication      | USA     | New York | 1969-12-25 | 
| Mountain Publication     | USA     | Houstan  | 1975-01-01 | 
| Summer Night Publication | USA     | New York | 1990-12-10 | 
+--------------------------+---------+----------+------------+
3 rows in set (0.00 sec)

Slideshow of MySQL Comparison Function and Operators

Previous: NULL Safe equal to operator (<=>)
Next: Greater than or equal operator(>=)



Follow us on Facebook and Twitter for latest update.