Subject Re: Help with query neaded
Author Zoran Zivkovic
--- In firebird-support@yahoogroups.com, Svein Erling Tysvær <svein.
erling.tysvaer@...> wrote:
>
> --- In firebird-support@yahoogroups.com, "Zoran Zivkovic" wrote:
> > My query (which doesn't give me what i need is):
> >
> > SELECT
> > A.SIFRA_PROIZ,
> > A.STANJE,
> > SPJ.STANJE
> > FROM ARTIKLI A
> > LEFT OUTER JOIN STANJE_PJ SPJ ON (SPJ.SIFRA_PROIZ=A.SIFRA_PROIZ)
> > WHERE A.SIFRA_PROIZ LIKE 'C%' AND SPJ.SIFRA_SKLAD=1
> >
> > Table Artikli has 1200 rows with field SIFRA_PROIZ starting with
> > 'c'. Table STANJE_PJ has 121 row with field SIFRA_PROIZ starting
> > with 'c' and sifra_sklad=1. I need query which will return 1200
> > rows, and in 3rd column I need NULLs where there is no
coresponding
> > record in Table STANJE_PJ. I hope this I was clear, :).
>
> Very clear Zile, and the answer to your problem is simple. Change
your
> query to
>
> SELECT A.SIFRA_PROIZ, A.STANJE, SPJ.STANJE
> FROM ARTIKLI A
> LEFT OUTER JOIN STANJE_PJ SPJ ON SPJ.SIFRA_PROIZ=A.SIFRA_PROIZ
> AND SPJ.SIFRA_SKLAD=1
> WHERE A.SIFRA_PROIZ STARTING 'C'
>
> Things you put in your LEFT JOIN affects what will be returned from
> the right table. Things put in your WHERE clause affects which rows
> are returned. By putting SPJ.SIFRA_SKLAD=1 in the WHERE clause, you
> actually changed your query to an inner JOIN (practically speaking).
>
> I also changed from LIKE to STARTING, since STARTING can use an
index.
>
> > P.S. I Still can't post messages from OE to newsgroup. Any help?
>
> The only thing I know is that the sender has to use the same address
> as the address subscribed to this list through yahoogroups. If
you've
> changed e-mail address, then you have to change your subscription as
well.
>
> HTH,
> Set
>

SET,

Thanks for the feedback.
It is amazing how much someone can learn from this list. I never
even
tried to put some additional condition in join clause. Actually, I
didn't
know it is possible!!!
Regards

Zile