top of page

SQL (2): Comparison




Today we're going to see how SQL can extract valuable information by doing data comparison.


Let's go.




First, see this example:


SELECT e.name AS Employee FROM Employee e, Employee m
    WHERE e.managerId = m.id AND e.salary > m.salary


SELECT defines you want to show in the output.


e.name means you want to show the employee's name in the output.


AS specifies the column name of the e.name row/data as Employee.


FROM means retrieving data from Employee table and assigns it to e and m respectively.


WHERE filters your target data by condition.


e.managerId = m.id is the first condition, which is used to pair up the employees with their managers by matching managerId and id (primary key).


AND states the second necessary condition e.salary > m.salary.


It further filters out the employee whose salary is higher than his/her manager.



Then we can see the output:


+----------+
| Employee |
+----------+
| Harmony  |
+----------+











Congratulations on completing this tutorial!


Don't hesitate to continue exploring SQL and experimenting with different scenarios.



See you in SQL (3)!








© 2023 Harmony Pang. All rights reserved.








Comments


bottom of page