SQLite Exercise: Display the job history that was done by any employee who is currently drawing more than 10000 of salary
Write a query to display the job history that was done by any employee who is currently drawing more than 10000 of salary.
Sample table : employees
+-------------+-------------+-------------+----------+--------------------+------------+------------+----------+----------------+------------+---------------+ | EMPLOYEE_ID | FIRST_NAME | LAST_NAME | EMAIL | PHONE_NUMBER | HIRE_DATE | JOB_ID | SALARY | COMMISSION_PCT | MANAGER_ID | DEPARTMENT_ID | +-------------+-------------+-------------+----------+--------------------+------------+------------+----------+----------------+------------+---------------+ | 100 | Steven | King | SKING | 515.123.4567 | 1987-06-17 | AD_PRES | 24000.00 | 0.00 | 0 | 90 | | 101 | Neena | Kochhar | NKOCHHAR | 515.123.4568 | 1987-06-18 | AD_VP | 17000.00 | 0.00 | 100 | 90 | | 102 | Lex | De Haan | LDEHAAN | 515.123.4569 | 1987-06-19 | AD_VP | 17000.00 | 0.00 | 100 | 90 | | 103 | Alexander | Hunold | AHUNOLD | 590.423.4567 | 1987-06-20 | IT_PROG | 9000.00 | 0.00 | 102 | 60 | | 104 | Bruce | Ernst | BERNST | 590.423.4568 | 1987-06-21 | IT_PROG | 6000.00 | 0.00 | 103 | 60 | | 105 | David | Austin | DAUSTIN | 590.423.4569 | 1987-06-22 | IT_PROG | 4800.00 | 0.00 | 103 | 60 | | 106 | Valli | Pataballa | VPATABAL | 590.423.4560 | 1987-06-23 | IT_PROG | 4800.00 | 0.00 | 103 | 60 | | 107 | Diana | Lorentz | DLORENTZ | 590.423.5567 | 1987-06-24 | IT_PROG | 4200.00 | 0.00 | 103 | 60 | | 108 | Nancy | Greenberg | NGREENBE | 515.124.4569 | 1987-06-25 | FI_MGR | 12000.00 | 0.00 | 101 | 100 | | 109 | Daniel | Faviet | DFAVIET | 515.124.4169 | 1987-06-26 | FI_ACCOUNT | 9000.00 | 0.00 | 108 | 100 | ........... | 206 | William | Gietz | WGIETZ | 515.123.8181 | 1987-10-01 | AC_ACCOUNT | 8300.00 | 0.00 | 205 | 110 | +-------------+-------------+-------------+----------+--------------------+------------+------------+----------+----------------+------------+---------------+
Sample table : Job_history
employee_id start_date end_date job_id department_id ----------- ---------- ---------- ---------- ------------- 102 1993-01-13 1998-07-24 IT_PROG 60 101 1989-09-21 1993-10-27 AC_ACCOUNT 110 101 1993-10-28 1997-03-15 AC_MGR 110 201 1996-02-17 1999-12-19 MK_REP 20 114 1998-03-24 1999-12-31 ST_CLERK 50 122 1999-01-01 1999-12-31 ST_CLERK 50 200 1987-09-17 1993-06-17 AD_ASST 90 176 1998-03-24 1998-12-31 SA_REP 80 176 1999-01-01 1999-12-31 SA_MAN 80 200 1994-07-01 1998-12-31 AC_ACCOUNT 90
SQLite Code:
-- Selecting all columns from the "job_history" table
SELECT jh.*
-- Specifying the primary table from which to retrieve the data, in this case, "job_history" (aliased as "jh")
FROM job_history jh
-- Performing an inner join with the "employees" table (aliased as "e") based on the common column "employee_id"
JOIN employees e
ON (jh.employee_id = e.employee_id)
-- Filtering the results to include only those rows where the salary is greater than 10000
WHERE salary > 10000;
Output:
employee_id start_date end_date job_id department_id ----------- ---------- ---------- ---------- ------------- 102 1993-01-13 1998-07-24 IT_PROG 60 101 1989-09-21 1993-10-27 AC_ACCOUNT 110 101 1993-10-28 1997-03-15 AC_MGR 110 201 1996-02-17 1999-12-19 MK_REP 20 114 1998-03-24 1999-12-31 ST_CLERK 50
Explanation:
The above SQLite query retrieves all columns from the "job_history" table and performs an inner join with the "employees" table based on the common column "employee_id." The results are then filtered to include only those rows where the salary is greater than 10000.
Here's a brief explanation of each part of SQLite code:
- SELECT clause:
- It selects all columns (*) from the "job_history" table.
- FROM clause:
- Specifies the primary table from which to retrieve the data, in this case, the "job_history" table. The table is given an alias "jh."
- JOIN clause:
- Performs an inner join with the "employees" table. The table is aliased as "e," and the join is based on the condition that the employee_id in the "job_history" table matches the employee_id in the "employees" table.
- ON clause:
- Specifies the join condition using the ON keyword. The condition is (jh.employee_id = e.employee_id), indicating that the "job_history" and "employees" tables are joined based on the common column "employee_id."
- WHERE clause:
- Filters the results to include only those rows where the salary is greater than 10000.
Go to:
PREV : Write a query to display job title, employee name, and the difference between the salary of the employee and minimum salary for the job.
NEXT : SQLite Exercises
Practice SQLite Online
Model Database

Structure of 'hr' database :
Improve this sample solution and post your code through Disqus.
What is the difficulty level of this exercise?
