Solved

highest attempt in table

Posted on 2009-07-08
3
214 Views
Last Modified: 2013-12-13
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
GROUP BY r.jobID

Open in new window

0
Comment
Question by:debbieau1
3 Comments
 
LVL 31

Expert Comment

by:RiteshShah
ID: 24810961
>>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?
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 24811232
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
GROUP BY j.jobID

Open in new window

0
 
LVL 1

Author Closing Comment

by:debbieau1
ID: 31601432
Thank you!     That is exactly what I needed.
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This article discusses four methods for overlaying images in a container on a web page
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question