Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

highest attempt in table

Posted on 2009-07-08
3
Medium Priority
?
236 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
This article discusses how to create an extensible mechanism for linked drop downs.
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 look for a specific file type in a local or remote server directory using PHP.

705 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