highest attempt in table

I am having a problem with a query and it is not returning the results I need.

In the following example (the field 'lev' is NOT providing the matching value for that record (for the 'attempt' that is output)

Hope that is clear enough
SELECT DISTINCT j.name, max(r.attempt) AS highest, j.active, j.jobID, r.lev
FROM (journals j
LEFT JOIN responses r ON r.jobID=j.jobID)
WHERE j.contactID = 220

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

>>Hope that is clear enough<<

sorry to say but doesn't seems much clear to me, can you please provide us with create table script, some data for that table and your desired results?
Guy Hengel [angelIII / a3]Billing EngineerCommented:
this should do:
SELECT j.name, r.attempt AS highest, j.active, j.jobID, r.lev
FROM journals j
LEFT JOIN responses r ON r.jobID=j.jobID
   AND r.attempt = ( SELECT MAX(i.attempt) FROM responses i WHERE i.jobID = j.JOBID )
WHERE j.contactID = 220

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
debbieau1Author Commented:
Thank you!     That is exactly what I needed.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.