Re: Joins... Urgent

From: John Vinson (jvinson_at_STOP_SPAM.WysardOfInfo.com)
Date: 02/28/04


Date: Fri, 27 Feb 2004 17:22:55 -0700

On Fri, 27 Feb 2004 14:16:09 -0800, "Mudassir Iqbal"
<Mudassiriqbal@yahoo.com> wrote:

>SELECT TabA.fldA
>FROM TabA left join TabB on TabA.FldA = TabB.FldA
>where
>TabB.FldA is nUll and TabB.FldB=66;

If there is no record in TabB that matches any record in TabA, then
the value of FldB will CERTAINLY not be equal to 66 - there isn't any
record at all so it can't have a value!

If you want to find records in TabA for which there is no
corresponding record in that subset of TabB which has FldB equal to
66, use a Subquery:

SELECT TabA.*
FROM TabA
WHERE NOT EXISTS
  (SELECT TabB.FldA FROM TabB
   WHERE TabB.FldA = TabA.FldA
   AND TabB.FldB = 66);

                  John W. Vinson[MVP]
    Come for live chats every Tuesday and Thursday
http://go.compuserve.com/msdevapps?loc=us&access=public



Relevant Pages

  • Re: Query Join no unique link
    ... NrSeq seems to be different but if you do not care about that then one ... Or you can just disregard the TabB. ... (yes the join fields are the same, but I don't have a unique link between ...
    (microsoft.public.sqlserver.programming)
  • Update TabA with value fromTabB
    ... TabA is a Detail Table, Col A belong to TabA ... TabB is a Header Table, ...
    (microsoft.public.sqlserver.programming)
  • Variables Update einer Tabelle
    ... ich habe schwierigkeiten eine Update-Klausel zu formulieren. ... Tabellen (TabA, TabB). ... Ich formuliers mal in Worten: ...
    (microsoft.public.de.german.entwickler.dotnet.datenbank)
  • Joins... Urgent
    ... I want values from TabA which are not in TabB ... Tab A ... Fld A Fld B ...
    (microsoft.public.access.queries)
  • Re: SQL: getting data for a null value column ??
    ... Thanks hrishy san ... so i have to take name from tabB only. ... PS: about union ... FROM taba a,tabb b where b.bbankcode=a.bankcode ...
    (comp.databases.oracle.server)