Solved

selecting only one record in inner join

Posted on 2016-07-21
3
47 Views
Last Modified: 2016-07-21
Hi experts, i have a long SQL query with inner join, but it retrieve a duplicat record as one of the table contain more thatn one reocrd with different  data
i need to retrieve only the last record in the table
select a.*, b.Institution,b.graduationYear,b.GPA, c.Quali, d.Lastqualification
from Applicant as a inner join Qualification as b on a.CPRNo = b.CPRNo
inner join Qualimain as c on b.code = c.code
inner join Qualisec as d on b.code = d.code and b.codese = d.codese
order by a.CPRNo

Open in new window


i need to get only the last record entered in Qualification table
id         cprno       institue      graduationYesr
--------------------------------------------------------------
1          20222       test            2011
2          20222       test2          2013
--------------------------------------------------------------

for example, from the above table i need only the second record to be listed

any suggestion
0
Comment
Question by:AZZA-KHAMEES
3 Comments
 
LVL 49

Accepted Solution

by:
Ryan Chong earned 250 total points
ID: 41722825
try:
select a.id, a.cprno, a.Institution, a.graduationYear, a.GPA, a.Quali, a.Lastqualification
from
(
select a.*, b.Institution,b.graduationYear,b.GPA, c.Quali, d.Lastqualification,
row_number() over (partition by a.CPRNo order by b.graduationYear desc) idx
from Applicant as a inner join Qualification as b on a.CPRNo = b.CPRNo
inner join Qualimain as c on b.code = c.code
inner join Qualisec as d on b.code = d.code and b.codese = d.codese
) a
where a.idx = 1
order by a.CPRNo

Open in new window

0
 
LVL 142

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 250 total points
ID: 41722869
0
 

Author Comment

by:AZZA-KHAMEES
ID: 41722876
ohh Sorry Rayan
your are correct
the query is working fine
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.‚Äč
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

911 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

16 Experts available now in Live!

Get 1:1 Help Now