[Solved] Simplify SQL query for me please [closed]


I am not sure if I got your question all clear, this query below will give you the latest employee record if there are multiple user records –

SELECT * FROM employmentrecords WHERE id IN(SELECT MAX(id) FROM employmentrecords 
    WHERE ((date_end >='2017-08-22' 
            OR date_end IS NULL 
            OR (date_end <='2017-08-22' AND date_end >='2017-08-08')) 
            AND date_hired <='2017-08-22') 
    GROUP BY employee_id) 
    AND company_id<>0
    and rownum = 1
    order by date_hired desc

JFYI, no need to use the table name as alias if there is only one table you are fetching the data from, it just makes it hard to read the query on go.

solved Simplify SQL query for me please [closed]