w3resource

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


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

Relational Algebra Tree:

Relational Algebra Tree: MySQL less than operator.

Slideshow of MySQL Comparison Function and Operators

Previous: LESS THAN OR EQUAL OPERATOR(<=)
Next: LIKE



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://www.w3resource.com/mysql/comparision-functions-and-operators/less-than-operator.php