w3resource

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


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 Expression: MySQL less than or equal operator.

Relational Algebra Tree:

Relational Algebra Tree: MySQL less than or equal operator.

Slideshow of MySQL Comparison Function and Operators

Previous: LEAST()
Next: LESS THAN OPERATOR(<)



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/mysql/comparision-functions-and-operators/less-than-or-equal-operator.php