Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

highest attempt in table

Posted on 2009-07-08
3
Medium Priority
?
240 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 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

772 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