Christian writes "I'm working on a query (view) that selects one distinct record from a table of applications per Applicant (APPL_APPLICANT) based on a calculated priority number. Currently, my query is able to return an application with the highest priority number (PRIORITY_CODE). However, an Applicant might have two applications that have the same priority number. When this happens, my query returns the two applications with the same priority number, instead of just returning one (because they both have the same priority number). Unfortunately, I need just exactly one record (just one highest priority number) so I can join the priority number with another table about the Applicant. Here is my current query:SELECT A.APPL_APPLICANT AS id, A.APPL_START_TERM AS start_term, A.APPL_CURRENT_STATUS AS app_stat, C.PCCOUNT, A.PRIORITY_CODEFROM [APPLICATIONS] AS ALEFT join (select DISTINCT APPL_APPLICANT, max(PRIORITY_CODE) as PRIORITY_CODE, count(DISTINCT PRIORITY_CODE) AS PCCOUNT from [APPLICATIONS] group by PRIORITY_CODE, APPL_APPLICANT) as C ON A.[APPL_APPLICANT] = C.[APPL_APPLICANT]GROUP BY A.APPL_CURRENT_STATUS, A.APPL_APPLICANT, A.APPL_START_TERM
There is only one table named APPLICATIONS:APPLICATION_ID (key)APPL_APPLICANT - (Applicant ID)APPL_START_TERMAPPL_CURRENT_STATUSPRIORITY_CODE
SQL Server 2003 (8.00.730) SP2 on Windows 2003 ServerCan you offer any help or guidance? I really appreciate it. Thank you!Christian Stuckstuckc at rider dot edu"