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 > Database Server Software > MySQL > Complicated query

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-23-04, 06:44
Manish Yadav Manish Yadav is offline
Registered User
 
Join Date: Aug 2004
Posts: 2
Arrow Complicated query

Hi all!!!

I'm facing problem in getting some info from two mysql tables..

i hv two tables TAB_A and TAB_B

TAB_A:

contact_id(int) | contact_name(varchar)
--------------------------------------
1 | XYZ
2 | ABC


TAB_B:

act_id(int) | contact_id(int) | act_status(Enum('C','D')
----------------------------------------------------
1 | 1 | D
2 | 1 | C
3 | 2 | C


Now, i want to select only thos contact name who :
Do not have any TAB_B.act_status = 'D'

so that on making query i should get only ABC

i'm not able to write any query for this.

Please help.


Thanks a lot
Reply With Quote
  #2 (permalink)  
Old 08-23-04, 07:17
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
Code:
select TAB_A.contact_name
  from TAB_A
inner
  join TAB_B
    on TAB_A.contact_id
     = TAB_B.contact_id
group
    by TAB_A.contact_name
having sum(case when TAB_B.act_status = 'D' 
                then 1 else 0 end)
     = 0
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 08-23-04, 07:57
Manish Yadav Manish Yadav is offline
Registered User
 
Join Date: Aug 2004
Posts: 2
HI !!!!


MANY MANY THANKS....

THE CODE WORKS.. EXACTLY WHAT I NEEDED..


THANKS A LOT

Manish
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