[Techtalk] SQL query question

Cynthia Kiser cnk at ugcs.caltech.edu
Mon Apr 28 16:36:58 UTC 2008


Its possible - but the syntax depends on your database version. What
you want is called an outer join. Basically you do an outer join of
the two tables, then grab only the rows in A that have no match in B.

I am going to guess you are using mysql. So from the docs
(http://dev.mysql.com/doc/refman/5.0/en/join.html):


 The { OJ ... LEFT OUTER JOIN ...}  syntax shown in the join syntax
 description exists only for compatibility with ODBC. The curly braces
 in the syntax should be written literally; they are not metasyntax as
 used elsewhere in syntax descriptions.

SELECT left_tbl.*
  FROM { OJ left_tbl LEFT OUTER JOIN right_tbl ON left_tbl.id = right_tbl.id }
  WHERE right_tbl.id IS NULL;



Quoting Walt <pippin at freeshell.org>:
> I'm not sure if this is even possible with SQL, but I'm
> hoping it is...
> 
> I have to tables and want to select all the entries from
> Table 1 that do not appear in Table 2. So far I've only
> been able to successfully select the entries that appear
> in both tables, which is helpful if I end up needing to
> delete them by hand, but will be a bit time-consuming...
> 
> I've tried doing some searching, but unfortunately don't
> even know what command or terms to search for.
> 
> Thanks for any help!
> Walt
> 
> -~
> 
> 
>      Freedom of the press is the reliable reasonable and moral
>      nature of freedom.  The character of the censored press
>      is the nondescript confusion of tyranny.
>                          Karl Marx 
> 
> _______________________________________________
> Techtalk mailing list
> Techtalk at linuxchix.org
> http://mailman.linuxchix.org/mailman/listinfo/techtalk

-- 
Cynthia N. Kiser
cnk at ugcs.caltech.edu


More information about the Techtalk mailing list