Solved

Return records not matching criteria using group by

Posted on 2008-10-06
1
161 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 32

Accepted Solution

by:
Daniel Wilson earned 500 total points
ID: 22650132
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In database programming, custom sort order seems to be necessary quite often, at least in my experience and time here at EE. Within the realm of custom sorting is the sorting of numbers and text independently (i.e., treating the numbers as number…
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

734 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