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

x
Solved

# MS SQL 2000 Query

Posted on 2009-04-12
Medium Priority
219 Views
I have two tables with one to many relationship namley employees (Emp) and qualifications (Qual). I want to select all employees with the most recent qualification. Each employee might have more than one qualification. The two tables are joined by the emp_cpr column. I tried the following SQL query :

SELECT Emp.CPR, Emp.name, Max(Qual.Date) AS Date
FROM Emp INNER JOIN Qual ON emp.cpr = Qual.cpr
GROUP BY Emp.cpr,emp.name

It's working  only if I select two columns from the first table namely emp_cpr and emp_name. I want to group all employees by cpr showing only thier latest qualification.

Thanks
0
Question by:AZZA-KHAMEES
[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
• 2

LVL 93

Expert Comment

ID: 24126215
SELECT e.cpr, q.QualDescr --guessing on the column name here!
FROM Emp e INNER JOIN
Qual q ON e.cpr = q.CPR INNER JOIN
(SELECT q2.cpr, Max(q2.Date) AS MaxDate
FROM Qual q2
GROUP BY q2.cpr) z ON q.cpr = z.cpr AND q.Date = z.MaxDate
0

LVL 93

Accepted Solution

Patrick Matthews earned 2000 total points
ID: 24126220
Sorry, make that

SELECT e.cpr, e.Name, q.QualDescr --guessing on the column name here!
FROM Emp e INNER JOIN
Qual q ON e.cpr = q.CPR INNER JOIN
(SELECT q2.cpr, Max(q2.Date) AS MaxDate
FROM Qual q2
GROUP BY q2.cpr) z ON q.cpr = z.cpr AND q.Date = z.MaxDate
0

Author Closing Comment

ID: 31569339
Thanks alot. It's working fine
0

## Featured Post

Question has a verified solution.

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

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
###### Suggested Courses
Course of the Month6 days, 23 hours left to enroll

#### 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.