Solved

selecting only one record in inner join

Posted on 2016-07-21
3
39 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
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 backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

747 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

10 Experts available now in Live!

Get 1:1 Help Now