MySQL less than operator
less than operator
MySQL less than operator checks whether an expression is less than the other.
Syntax:
<
MySQL Version: 8.0
Example: MySQL less than operator(<)
The following MySQL statement will fetch those publishers from the publisher table that has less than 8 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:
-- Select the columns pub_name, country, pub_city, and no_of_branch from the publisher table
SELECT pub_name, country, pub_city, no_of_branch
-- From the table named publisher
FROM publisher
-- Filter the results to include only those rows where no_of_branch is less than 8
WHERE no_of_branch < 8;
Explanation:
- SELECT pub_name, country, pub_city, no_of_branch:
- This line specifies the columns to be retrieved from the database.
- pub_name: Name of the publisher.
- country: Country where the publisher is located.
- pub_city: City where the publisher is located.
- no_of_branch: Number of branches the publisher has.
- FROM publisher:
- This line indicates the table from which the data should be retrieved.
- publisher: The name of the table in the database.
- WHERE no_of_branch < 8:
- This line filters the results to include only those publishers that have fewer than 8 branches.
- no_of_branch < 8: A condition that ensures only rows where the number of branches is less than 8 are selected.
Output:
mysql> SELECT pub_name,country,pub_city,no_of_branch
-> FROM publisher
-> WHERE no_of_branch<8;
+------------------------------+-----------+-----------+--------------+
| 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.00 sec)
Relational Algebra Expression:

Relational Algebra Tree:

Slideshow of MySQL Comparison Function and Operators
PREV : LESS THAN OR EQUAL OPERATOR(<=)
NEXT : LIKE
