Solved

Sql query

Posted on 2011-09-15
6
195 Views
Last Modified: 2012-05-12
Hi,

I need to write a query that gives me following results.

Table :

EDUID	      START_TIME                 DTMF

4e418e4f 2011-08-09 22:48:53.827 2164724036
4e418e55 2011-08-09 22:51:44.687 2125539806
4e419196 2011-08-09 22:58:36.950 2125354614
4e419181 2011-08-09 22:59:08.697 2
4e419188 2011-08-09 22:59:16.347 4642260017
4e419181 2011-08-09 22:59:28.597 nmt              
4e419196 2011-08-09 22:59:30.053 2164423695
4e41919d 2011-08-09 22:59:36.387 Disc
4e419198 2011-08-09 22:59:31.683 nmt              
4e418e4f	2011-08-09 22:59:30.530 224243
4e419188 2011-08-09 22:59:39.347 4642265000

Open in new window



Query should give last records of each EDUID value.

Expected Result:

EDUID       START_TIME     DTMF
4e418e4f	2011-08-09 22:59:30.530 224243
4e419181  2011-08-09 22:59:28.597 nmt
4e419196  2011-08-09 22:59:30.053 2164423695
4e418e55  2011-08-09 22:51:44.687 2125539806
4e419188  2011-08-09 22:59:39.347 4642265000
4e41919d  2011-08-09 22:59:36.387  Disc
4e419198  2011-08-09 22:59:31.683  nmt

Open in new window


Thanks.




0
Comment
Question by:fiore45
[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
6 Comments
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 36545864
SELECT t1.EDUID, t1.START_TIME, t1.DTMF
FROM SomeTable t1 INNER JOIN
    (SELECT t2.EDUID, MAX(t2.START_TIME) AS START_TIME
    FROM SomeTable t2
    GROUP BY t2.EDUID) x ON t1.EDUID = x.EDUID AND t1.START_TIME = x.START_TIME
0
 
LVL 10

Expert Comment

by:pramodsk40
ID: 36546014
why dont you use order by asc or desc which ever way you want for starttime or eduid ?
0
 
LVL 50

Accepted Solution

by:
Lowfatspread earned 500 total points
ID: 36547977
select eduid,starttime,dtmf
from (select x.*
               ,row_number() over (partition by eduid order by starttime desc) as rn
                      from yourtable as x
         ) as y
where y.rn=1
order by 1
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 9

Expert Comment

by:sachinpatil10d
ID: 36548038
select * from Test1 where START_TIME in (select MAX(start_time) start_time from test1 group by eduid)
0
 
LVL 50

Expert Comment

by:Lowfatspread
ID: 36548106
@sachinpatil10d
   the subquery would need to be corelated otherwise multiple rows per eduid could be present....
0
 
LVL 9

Expert Comment

by:sachinpatil10d
ID: 36578556
@Lowfatspread

multiple rows case would be if the start_time is same for same eduid

so can i think this query should work

select distinct * from Test1 where START_TIME in (select MAX(start_time) start_time from test1 group by eduid)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
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.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

623 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