Solved

Return records not matching criteria using group by

Posted on 2008-10-06
1
150 Views
Last Modified: 2012-05-05
I have a table that contains text type information for a given case.  There can be 1 or more text type for a given case.  I am trying to write a query that will return only those case numbers that do not have a text_type of resolution for any of the text types for a given case

 Here is some sample  data

Case_id     Text_Type_Seq   Text_Type        
1                1                           Notes
1                2                           Notes
1                3                           Resolution
2                1                           Notes
2                2                           Notes
2                3                           Notes
2                4                           Notes
3                1                           Notes
3                2                           Notes
4                1                           Notes
4                2                           Resolution


Using the sample data above:

The query should only return

Case_ID
2
3

Since case 1 and 4 have a text type of resolution
0
Comment
Question by:johnnyg123
1 Comment
 
LVL 32

Accepted Solution

by:
Daniel Wilson earned 500 total points
Comment Utility
Select distinct Case_ID
From MyTable T1
Where Not Exists (Select Case_ID From MyTable T2 Where T1.Case_ID = T2.Case_ID And T2.Text_type = 'Resolution')
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now