|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
SIMPLE Left OUTER JOIN QuestionI 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 pmud wrote:
Show quote > Hi, Try this:> > 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 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 -- 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 > -- > > |
|||||||||||||||||||||||