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)
 sql query help

Author  Topic 

nimesh
Starting Member

1 Post

Posted - 2005-12-15 : 12:56:40
hi

i have a table with multiple fields let me show you an example

Event_ID Occurrence_nbr seq_event_nmbr cause_fac
>> 20001204X0000 1 1 cause
>> 20001204X0000 1 2 cause
>> 20001204X0000 1 3 factor
>> 20001204X0001 1 1 cause
>> 20001204X0001 1 2 cause

what i want is based on a event_id and occurrence_nbr i want the first seq_event_nmbr which is a cause, i just want the first seq_event_nmbr and not all.

Is this possible?

thanks

nimesh

rockmoose
SQL Natt Alfen

3279 Posts

Posted - 2005-12-15 : 13:14:00
Hi nimesh,

Welcome to Sql Team!

select Event_ID, Occurrence_nbr, min(seq_event_nmbr) as seq_event_nmbr
from yourTable
group by Event_ID, Occurrence_nbr
where cause_fac = 'cause'

rockmoose
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-12-16 : 00:49:46
Small modification on rocky's code
Where clause should be followed by Group by if any

select Event_ID, Occurrence_nbr, min(seq_event_nmbr) as seq_event_nmbr
from yourTable
where cause_fac = 'cause'
group by Event_ID, Occurrence_nbr



Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -