Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Easy Query Alluding Me.

Author  Topic 

jfieck
Starting Member

6 Posts

Posted - 2005-06-02 : 17:45:27
Hello,
I have what I hope is an easy query that I can't seem to get. Consider this table:

--------------------------
- TIME -- TYPE -
--------------------------
- 4:00 -- AM -
- 5:00 -- AM -
- 5:00 -- PM -
--------------------------

I need a query that see that there are two rows that have the same TIME value and only retuns one of them. Either of them will do. The aceptable out come would be either of these:

--------------------------
- TIME -- TYPE -
--------------------------
- 4:00 -- AM -
- 5:00 -- AM -
--------------------------

or

--------------------------
- TIME -- TYPE -
--------------------------
- 4:00 -- AM -
- 5:00 -- PM -
--------------------------

If anyone can help with this it would be appriciated. Thanks.

SamC
White Water Yakist

3467 Posts

Posted - 2005-06-02 : 18:10:23
SELECT DISTINCT Time, Type
FROM ...
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2005-06-02 : 18:11:59
SELECT [Time], MAX(Type)
FROM YourTable
GROUP BY [Time]

Tara
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2005-06-02 : 18:12:30
quote:
Originally posted by SamC

SELECT DISTINCT Time, Type
FROM ...



DISTINCT won't work because the TYPE is different. They aren't duplicate rows.

Tara
Go to Top of Page

jfieck
Starting Member

6 Posts

Posted - 2005-06-02 : 18:17:40
This acually doesn't work. I had tried this first. It still returns both lines. I think because the TYPE values are different it makes each row distinct.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2005-06-02 : 18:18:50
Ummm, did you see my solution?

Tara
Go to Top of Page

jfieck
Starting Member

6 Posts

Posted - 2005-06-02 : 18:25:53
Sorry Tara,
I didn't see your reply before I sent mine. Thanks.
Go to Top of Page
   

- Advertisement -