I need to create a SQL query to retrieve all the values from one unique row entry in a table called JOBS.
But to do so I need to use a table called EMPLOYEES which has a foreign key to the JOBS table.
The condition is to return the job_title from the table JOBS that has its job_id more times repeated in the EMPLOYEES table.
I need to do it with one SQL statement.
Desired output:
Stock Clerk
This is the query I have
SELECT job_id
FROM (SELECT job_id FROM employees GROUP BY job_id ORDER BY COUNT(*) desc)
WHERE ROWNUM <= 1;
but is not good enough because it is job_title from EMPLOYEES what I need.
Do you have any idea how can I do it? I am using an Oracle 11g database
This is how my tables look like:
EMPLOYEES

JOBS

Don’t remember offhand if you can use LIMIT 1 in oracle, but if not then
Also note that if the top 2+ job id’s are equal, it will only print one of them (i.e. if SA_REP and ST_CLERK both appeared 4 times, only one of them would be shown)
It’s not clear what your requirements are for this, but the above queries would only return one of them