Subject | RE: [firebird-support] Re: SQL for master-detail |
---|---|
Author | Leyne, Sean |
Post date | 2007-12-27T18:15:30Z |
Dan,
Select *
from
MasterInfo m
where
NOT EXISTS(
select 1
from DetailInfo d
where m.Master_ID = d.Master_ID
)
Sean
> > I am looking for all of the master records that have one or nodetail
> > records.The much better/faster approach is to use NOT EXISTS:
> >
> > Select Master_ID from MasterInfo where Master_ID (select Master_ID
> > from DetailInfo where [less then one record])
> >
> > Can this be done without a stored proc?
>
> Sure:
>
> Select * from MasterInfo m
> where
> (select count(*)
> from DetailInfo d
> where m.Master_ID = d.Master_ID) <= 1
Select *
from
MasterInfo m
where
NOT EXISTS(
select 1
from DetailInfo d
where m.Master_ID = d.Master_ID
)
Sean