Subject | Re: help with a select, i m out of ideas. |
---|---|
Author | Adam |
Post date | 2006-03-31T09:40:55Z |
--- In firebird-support@yahoogroups.com, Svein Erling Tysvær
<svein.erling.tysvaer@...> wrote:
think, but the exists is just as easy to read. The left join solution
would also work with your correction.
Adam
<svein.erling.tysvaer@...> wrote:
>Guilty as charged. Well spotted.
> As always, a very good and educative answer, Adam. I just think that
> the LEFT JOIN part is incorrect this time:
>
> > Using Left Join:
> >
> > select *
> > from clientes C
> > left join vendas v on (V.cli_cod=C.cli_cod)
> > where V.cli_cod IS NOT NULL
> > and V.vnd_data BETWEEN '2006-1-01' AND '2006-1-31';
>
> To me this seems like an ordinary inner JOIN. Shouldn't it be
>
> select *
> from clientes C
> left join vendas v on (V.cli_cod=C.cli_cod
> and V.vnd_data BETWEEN '2006-1-01' AND '2006-1-31')
> where V.cli_cod IS NULL
>
> i.e. put all things that's part of the record that shouldn't exist inI find the 'in' syntax the easiest to write because that is how I
> the JOIN clause, and then just the IS NULL in the WHERE clause to
> ascertain there ain't any such records.
>
> Myself, I find the NOT EXISTS solution to be the easiest to understand
> and quickest to execute, so I don't use IN (<subselect>) or LEFT JOIN
> ... WHERE <right table PK> IS NULL unless there is a very good reason.
>
think, but the exists is just as easy to read. The left join solution
would also work with your correction.
Adam