MySQL less than or equal operator
less than or equal operator
MySQL less than or equal operator checks whether an expression is either less than or equal to another expression.
Syntax:
<=
MySQL Version: 8.0
Example:
The following MySQL statement will fetch those publishers from the publisher table who have less than or equal to 6 branch offices.
Sample table: publisher
+--------+------------------------------+-----------+-----------+----------------+--------------+------------+ | pub_id | pub_name | pub_city | country | country_office | no_of_branch | estd | +--------+------------------------------+-----------+-----------+----------------+--------------+------------+ | P001 | Jex Max Publication | New York | USA | New York | 15 | 1969-12-25 | | P002 | BPP Publication | Mumbai | India | New Delhi | 10 | 1985-10-01 | | P003 | New Harrold Publication | Adelaide | Australia | Sydney | 6 | 1975-09-05 | | P004 | Ultra Press Inc. | London | UK | London | 8 | 1948-07-10 | | P005 | Mountain Publication | Houstan | USA | Sun Diego | 25 | 1975-01-01 | | P006 | Summer Night Publication | New York | USA | Atlanta | 10 | 1990-12-10 | | P007 | Pieterson Grp. of Publishers | Cambridge | UK | London | 6 | 1950-07-15 | | P008 | Novel Publisher Ltd. | New Delhi | India | Bangalore | 10 | 2000-01-01 | +--------+------------------------------+-----------+-----------+----------------+--------------+------------+
Code:
-- Selects the columns pub_name, country, pub_city, and no_of_branch from the publisher table
SELECT pub_name, country, pub_city, no_of_branch
-- Specifies the table from which to retrieve the data
FROM publisher
-- Filters the rows to include only those where the number of branches (no_of_branch) is less than or equal to 6
WHERE no_of_branch <= 6;
Explanation:
- SELECT pub_name, country, pub_city, no_of_branch:
- This part of the query specifies the columns to be retrieved from the publisher table.
- pub_name: The name of the publisher.
- country: The country where the publisher is located.
- pub_city: The city where the publisher is located.
- no_of_branch: The number of branches the publisher has.
- FROM publisher:
- This specifies the table from which to retrieve the data. In this case, it is the publisher table.
- WHERE no_of_branch <= 6:
- This clause filters the rows to include only those where the number of branches (no_of_branch) is less than or equal to 6.
- It ensures that only publishers with 6 or fewer branches are included in the results.
Output:
mysql> SELECT pub_name,country,pub_city,no_of_branch
-> FROM publisher
-> WHERE no_of_branch<=6;
+------------------------------+-----------+-----------+--------------+
| pub_name | country | pub_city | no_of_branch |
+------------------------------+-----------+-----------+--------------+
| New Harrold Publication | Australia | Adelaide | 6 |
| Pieterson Grp. of Publishers | UK | Cambridge | 6 |
+------------------------------+-----------+-----------+--------------+
2 rows in set (0.02 sec)
Relational Algebra Expression:

Relational Algebra Tree:

Slideshow of MySQL Comparison Function and Operators
PREV : LEAST()
NEXT : LESS THAN OPERATOR(<)
