Link to home
Start Free TrialLog in
Avatar of hdcowboyaz
hdcowboyazFlag for United States of America

asked on

SQL Syntax

This select query is correct. I need to update j.LAST_WORK in the job table with the results from the query.

SELECT j.JOB, MAX(l.DATE_WORK) 'LAST DAY WORKED'
FROM job j, labor l
WHERE j.JOB_ID = l.JOB_ID
AND j.JSTATUS = 'I'
AND j.DELETED = 'N'
AND l.DELETED = 'N'
GROUP BY j.JOB_ID;
ASKER CERTIFIED SOLUTION
Avatar of PortletPaul
PortletPaul
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hdcowboyaz

ASKER

Couple typos but it worked...thanks

UPDATE job AS target
INNER JOIN (
            SELECT j.JOB_ID, MAX(l.DATE_WORK) AS LAST_DAY_WORKED
            FROM job j
            INNER JOIN labor l ON j.JOB_ID = l.JOB_ID
            WHERE j.JSTATUS = 'I'
            AND j.DELETED = 'N'
            AND l.DELETED = 'N'
            GROUP BY j.JOB_ID
           ) AS source
             ON target.JOB_ID = source.JOB_ID
SET target.LAST_WORK = source.LAST_DAY_WORKED;
"couple of typos"?
do you mean the lower case job in line 1?

as you didn't identify the field to update I did say I had made a guess, so the difference in the last line isn't a typo - is was an assumed field name.

I cannot see any other differences. Are there any others?

Anyway, you got the idea and that is what we aim at. Thanks for the quick closure that's always appreciated.

Cheers, Paul