In my query each CLC_ID can have multiple CLC_Contact_SEQ as every new entry creates a new higher number for that member. I need to bring back the greatest entry for each ID number. Right now I just have them ordered so each ID I can see all of the entries. I am new to SQL and any help would be GREAT! Select CLC_CLNT_NUM, CLC_CONTACT_TYPE, CLC_CONTACT_SEQ, CLC_CONTACT_DATa, CLC_ID FROM dbo.CLIENT_CONTACT_INFO WHERE cLC_CONTACT_TYPE = 'INTR' ORDER by CLC_CLNT_NUM
This is untested and off the top of my head, but if you just want to get the greatest `CLC_Contact_Seq` then you can use max like: select CLC_ID, max(CLC_Contact_Seq) as CLC_contact_seq from dbo.CLIENT_CONTACT_INFO group by CLC_ID If you want to bring back the other columns, but only for the row that has the max contact sequence, then one approach is to do an inner join to the results of the above query. That would look something like: Select i1.CLC_CLNT_NUM, i1.CLC_CONTACT_TYPE, i1.CLC_CONTACT_SEQ, i1.CLC_CONTACT_DATa, i1.CLC_ID From dbo.CLIENT_CONTACT_INFO i1 inner join (select CLC_ID, max(CLC_Contact_Seq) as CLC_contact_seq from dbo.CLIENT_CONTACT_INFO group by clc_id) i2 on i1.clc_id = i2.clc_id and i1.clc_contact_seq = i2.clc_contact where i1.cLC_CONTACT_TYPE = 'INTR' order by i1.CLC_CLNT_NUM That would certainly not be the only option, but it is one of the conceptually simpler ones. Essentially, it is filtering the results of the table by the rows that have the greatest contact sequence for that ID number.
Another approach would be to use the [ROW_NUMBER] function: SELECT CLC_CLNT_NUM, CLC_CONTACT_TYPE, CLC_CONTACT_SEQ, CLC_CONTACT_DATA, CLC_ID, ROW_NUMBER() OVER (PARTITION BY CLC_CLNT_NUM ORDER BY CLC_CONTACT_SEQ DESC) AS RowNum FROM dbo.CLIENT_CONTACT_INFO WHERE RowNum = 1 :