Solved

highest attempt in table

Posted on 2009-07-08
3
200 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 142

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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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…
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…

863 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now