If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Listing rows "missing" information?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-23-05, 13:39
bla4free bla4free is offline
Registered User
 
Join Date: Jan 2005
Posts: 165
Listing rows "missing" information?

Here is how part of our database works. We have a table called "Events." Inside the "Events" table, we list various events which takes place for each of our clients. The first event for any client should be "Opened Case." However, some of my employees have not been listing this event so we do not know when the case was actually opened. In theory, all cases should have an "Opened Case" event in them. Is there a way to query that table to find which cases do not contain that event? Or is that more a programming issue? Thanks for any help?
Reply With Quote
  #2 (permalink)  
Old 02-23-05, 13:49
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,605
I'd suggest something like:
Code:
SELECT DISTINCT caseID
   FROM events AS a
   WHERE NOT EXISTS (SELECT *
      FROM events AS b
      WHERE  b.caseID = a.caseID
         AND 'Case Opened' = b.eventType)
   ORDER BY caseID
-PatP
Reply With Quote
  #3 (permalink)  
Old 02-23-05, 14:04
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
or something like --
Code:
select caseID
  from events 
group
    by caseID
having 0 
     = sum(
        case when eventType = 'Case Opened'
             then 1 else 0 
         end )
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #4 (permalink)  
Old 02-23-05, 14:15
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,605
My, aren't we feeling deviant today! Heck, Rudy's solution will even work in MySQL!

-PatP
Reply With Quote
  #5 (permalink)  
Old 02-23-05, 14:27
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
deviant? heh

i was just thinking that yours involves a join (expensive), a NOT EXISTS (expensive), and a sort to remove dupes (expensive)

mine's just one sort, to do grouping

[offtopic]hey pat, did you give that Sock Hop channel a try? i was hoping you'd come back with some comment like "oh wow, i love that stuff!" (which was my reaction)[/offtopic]
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On