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

x
?
Solved

selecting only one record in inner join

Posted on 2016-07-21
3
Medium Priority
?
87 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
[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 53

Accepted Solution

by:
Ryan Chong earned 1000 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 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 1000 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

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

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

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
I have a large data set and a SSIS package. How can I load this file in multi threading?
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

721 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