Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select First & Last

Status
Not open for further replies.

MickDub

Programmer
Apr 19, 2006
9
IE
HI all

Quick one

I pulling details from tabel and one the parts is to select the first time and last time in a day that a user writes to the tabel

Example

ID Time User Ext
1 08:00 1 A
2 08:30 1 A
3 08:45 1 A
4 09:00 1 A
5 10:00 1 A

What i need to return are the first tiem and last time
so woudl need

user Start End Ext
1 08:00 10:00 A

Thanks in Advance

Mick
 
Looks like standard aggregate query to me:
Code:
select [User], Min([Time]) as Start, Max([Time]) as [end], Ext
from myTable
-- where [User] = 1
group by [User], Ext

------
[small]<this is sig>
select stuff(stuff(replicate('<P> <B> ', 14), 109, 0, '<.'), 112, 0, '/')
</this is sig>[/small]
[banghead]
 
On top of my head
Code:
SELECT MyTable.User, 
       Tbl1.Start,
       Tbl2.End,
       Ext
FROM MyTable
INNER JOIN 
(SELECT User, MIN(Time) AS Start FROM MyTable GROUP BY User) Tbl1 ON MyTable.user = Tbl1.User,
INNER JOIN 
(SELECT User, MAX(Time) AS End FROM MyTable GROUP BY User) Tbl2 ON MyTable.user = Tbl2.User
FROM MyTable
GROUP BY MyTable.User, 
         Tbl1.Start,
         Tbl2.End,
         Ext






Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
 
LOL
Why I send such complicate SELECT :eek:)))))
Maybe I need more beer.

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
 
cheers lads forgot all about min & max option
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top