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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

select duplicates

Status
Not open for further replies.

fmt

Programmer
Aug 5, 2005
53
US
Hello,
How do I get max tag1 for given distict dates?

DATE TAG1
2005-10-08 06:15:00.000 0
2005-10-08 06:15:00.000 1
2005-10-08 06:30:00.000 0
2005-10-08 06:30:00.000 1
2005-10-08 06:45:00.000 1
2005-10-08 07:00:00.000 0
2005-10-08 07:15:00.000 0

I need to see something like

DATE TAG1
2005-10-08 06:15:00.000 1
2005-10-08 06:30:00.000 1
2005-10-08 06:45:00.000 1
2005-10-08 07:00:00.000 0
2005-10-08 07:15:00.000 0

Thanks
 
Thanks cLFlaVA !!!
but I have one more field to be selected. If I select that field the results are not same.
Date Tag1 Tag2
2005-10-08 09:00:00.000 0 0
2005-10-08 09:00:00.000 1 1
2005-10-08 09:15:00.000 0 0
2005-10-08 09:15:00.000 1 0
2005-10-08 09:15:00.000 1 1
2005-10-08 09:30:00.000 0 0
2005-10-08 09:30:00.000 1 0
2005-10-08 09:30:00.000 1 1
2005-10-08 09:45:00.000 0 0

I need something like
Date Tag1 Tag2
2005-10-08 09:00:00.000 1 1
2005-10-08 09:15:00.000 1 1
2005-10-08 09:30:00.000 1 1
2005-10-08 09:45:00.000 0 0

 
Try:
Code:
select A.*
from myTable A
inner join
(    select [Date], Max(Tag1) as maxTag1
    from myTable
    group by [Date]
) B on A.[date]=B.[date] and A.Tag1 = B.maxTag1
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top