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 > display records that do not exist in another table

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-04-04, 06:17
shani shani is offline
Registered User
 
Join Date: Sep 2003
Location: Pakistan, Karachi
Posts: 22
Unhappy display records that do not exist in another table

hi all,

I have following tables and respective fields:
models(model_code,display_name);
another table
group_models(group_code,model_code);

I want to display those models that do not exist in the current group.. the group_code is the code of the group..

I have tried following query but it does not return anything from it... my query is

select distinct a.model_code, a.display_name from models a,group_models b where b.model_code<>a.model_code and b.group_code='0012' order by a.display_name

I also tried following nested query it says that I have an error in the sql syntax :

select distinct model_code, display_name
from models
where model_code not in (select distinct model_code from group_models where group_code='0012')


Will be waiting for an urgent response... as this really is an urgent matter

Regards
Shani
Reply With Quote
  #2 (permalink)  
Old 08-04-04, 14:37
yellowmarker yellowmarker is offline
Registered User
 
Join Date: Jul 2004
Location: Dundee, Scotland
Posts: 107
select distinct a.model_code, a.display_name from models a,group_models b where b.model_code=a.model_code and b.group_code!='0012' order by a.display_name

re the nested query, which version of MySQL are you using?
Reply With Quote
  #3 (permalink)  
Old 08-06-04, 14:21
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Code:
select a.model_code
     , a.display_name 
  from models a
left outer
  join group_models b 
    on a.model_code 
     = b.model_code
   and b.group_code = '0012' 
 where b.model_code is null
order 
    by a.display_name
__________________
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