Data that exists only on one table

Hello,

I have 2 tables:

COMIC

id_comic (INT Autonumber, unique)
id_compra (CHAR 15, not necessarily unique)

-------------------

DTE

id_dte (Int Autonumber, unique)
id_compra (CHAR 15, Unique)
tipoDte (int)

I need to know what COMIC.id_compra Exists only on COMIC where (DTE.TipoDte ='33' or DTE.TipoDte='39')

Thanks.
jsbxAsked:
Who is Participating?
 
Mark WillsTopic AdvisorCommented:
Ahhh... OK, then you want something more like -  although not exactly sure of what you want with TipoDTE

select C.id_comic, C.id_compra         
from comic c
where c.id_compra not in (select id_compra from DTE where (TipoDte ='33' or TipoDte='39'))

Open in new window


And (TipoDte ='33' or TipoDte='39') should be written as TipoDte in ('33','39')

or possibly  TipoDte not in ('33','39')
0
 
Mark WillsTopic AdvisorCommented:
Something like :
select C.id_comic, C.id_compra              -- can add the d.* columns if needed
from comic c
inner join DTE d on d.id_compra = c.id_compra
where (D.TipoDte ='33' or D.TipoDte='39') 

Open in new window

0
 
jsbxAuthor Commented:
Mark,

That shows id_compra that exist on both tables.

I need to know what COMIC.id_compra Exists only on COMIC and do not exist in DTE
0
 
awking00Commented:
select id_compra from COMIC
where not exists
(select 1 from DTE
 where COMIC.id_compra = DTE.id_compra
 and TipoDte in ('33','39'));
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.