w3resource

MySQL greater than operator

greater than operator

MySQL greater than operator checks whether an expression is greater than another expression.

Syntax:

>

MySQL Version: 8.0

Example: MySQL greater than operator

The following MySQL statement will fetch those publishers from the publisher table who have more than 10 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:


-- This query selects specific columns from the 'publisher' table where the number of branches is greater than 10.
SELECT pub_name, country, pub_city, no_of_branch 
-- This statement specifies the columns to be retrieved: 'pub_name', 'country', 'pub_city', and 'no_of_branch'.
FROM publisher
-- This part of the query specifies the table from which data is being retrieved, which is 'publisher'.
WHERE no_of_branch > 10;
-- This clause filters the rows to include only those where the 'no_of_branch' column has a value greater than 10.

Explanation:

  • The purpose of this SQL query is to retrieve information about publishers that have more than 10 branches.

  • SELECT pub_name, country, pub_city, no_of_branch: This part of the query specifies the columns to be selected from the 'publisher' table. It includes the publisher's name (pub_name), country (country), city (pub_city), and the number of branches (no_of_branch).

  • FROM publisher: This part specifies the table from which the data is being selected, which is the 'publisher' table.

  • WHERE no_of_branch > 10: This clause filters the results to include only those rows where the no_of_branch column has a value greater than 10. This ensures that only publishers with more than 10 branches are included in the results.

Output:

mysql> SELECT pub_name,country,pub_city,no_of_branch 
    -> FROM publisher
    -> WHERE no_of_branch>10;
+----------------------+---------+----------+--------------+
| pub_name             | country | pub_city | no_of_branch |
+----------------------+---------+----------+--------------+
| Jex Max Publication  | USA     | New York |           15 | 
| Mountain Publication | USA     | Houstan  |           25 | 
+----------------------+---------+----------+--------------+
2 rows in set (0.00 sec)

Relational Algebra Expression:

Relational Algebra Expression: MySQL greater than operator.

Relational Algebra Tree:

Relational Algebra Tree: MySQL greater than operator.

Slideshow of MySQL Comparison Function and Operators

PREV : Greater than or equal operator(>=)
NEXT : GREATEST()



Follow us on Facebook and Twitter for latest update.