Home All Groups Group Topic Archive Search About

SIMPLE Left OUTER JOIN Question

Author
15 Dec 2005 9:26 PM
pmud
Hi,

I have to select a fiels from one table which is not presnt in both the
other 2 tables.. What will be the query for this..?

I used the following but it showes results where the field was present in
one table..i.e it showed wrong data.. Here is what I used:

Select MDN from
ActivityLogs Left OUTER JOIN PlanActivations on ActivityLogs.MDN
=PlanActivations.MobileID LEFT OUTER JOIN FeatureActivations on
ActivityLogs.MDN=FeatureActivations.MobileID
WHERE (ctivityLogs.MDN<>atureActivations.MobileID) AND ( ActivityLogs.MDN
<>anActivations.Mobile)

Any help is highly appreciated.

Thanks
--
pmud

Author
15 Dec 2005 9:35 PM
David Portas
pmud wrote:

Show quote
> Hi,
>
> I have to select a fiels from one table which is not presnt in both the
> other 2 tables.. What will be the query for this..?
>
> I used the following but it showes results where the field was present in
> one table..i.e it showed wrong data.. Here is what I used:
>
> Select MDN from
> ActivityLogs Left OUTER JOIN PlanActivations on ActivityLogs.MDN
> =PlanActivations.MobileID LEFT OUTER JOIN FeatureActivations on
> ActivityLogs.MDN=FeatureActivations.MobileID
> WHERE (ctivityLogs.MDN<>atureActivations.MobileID) AND ( ActivityLogs.MDN
> <>anActivations.Mobile)
>
> Any help is highly appreciated.
>
> Thanks
> --
> pmud

Try this:

SELECT A.mdn
FROM ActivityLogs AS A
LEFT JOIN PlanActivations AS P
  ON A.mdn = P.mobileid
LEFT JOIN FeatureActivations AS F
  ON A.mdn = F.mobileid
WHERE P.mobileid IS NULL
  AND F.mobileid IS NULL ;

If that's not it, please post DDL, sample data and show the result you
want so that we don't have to keep guessing.

--
David Portas
SQL Server MVP
--
Author
20 Dec 2005 12:08 AM
Arvander
Left join to both tables and test for Null for the same field in both tables.

Show quote
"David Portas" wrote:

> pmud wrote:
>
> > Hi,
> >
> > I have to select a fiels from one table which is not presnt in both the
> > other 2 tables.. What will be the query for this..?
> >
> > I used the following but it showes results where the field was present in
> > one table..i.e it showed wrong data.. Here is what I used:
> >
> > Select MDN from
> > ActivityLogs Left OUTER JOIN PlanActivations on ActivityLogs.MDN
> > =PlanActivations.MobileID LEFT OUTER JOIN FeatureActivations on
> > ActivityLogs.MDN=FeatureActivations.MobileID
> > WHERE (ctivityLogs.MDN<>atureActivations.MobileID) AND ( ActivityLogs.MDN
> > <>anActivations.Mobile)
> >
> > Any help is highly appreciated.
> >
> > Thanks
> > --
> > pmud
>
> Try this:
>
> SELECT A.mdn
>  FROM ActivityLogs AS A
>  LEFT JOIN PlanActivations AS P
>   ON A.mdn = P.mobileid
>  LEFT JOIN FeatureActivations AS F
>   ON A.mdn = F.mobileid
>  WHERE P.mobileid IS NULL
>   AND F.mobileid IS NULL ;
>
> If that's not it, please post DDL, sample data and show the result you
> want so that we don't have to keep guessing.
>
> --
> David Portas
> SQL Server MVP
> --
>
>

AddThis Social Bookmark Button