Subject Re: Self join
Author Adam
--- In firebird-support@yahoogroups.com, Damir Tesanovic <tdamir@...>
wrote:
>
> Hi!
> I have a one table containing:
> shop_id, barcode, amount
> 1, 12345, 54
> 1, 12346, 34
> 1, 34234, 23
> 2, 12345, 32
> 2, 10000, 12
> 3, 43245, 2
>
> I tryed with
> SELECT A.barcode, B.barcode FROM shops A LEFT JOIN shops B ON
(A.barcode =
> B.barcode) WHERE A.shop_id = 1 AND B.shop_id = 2;
> command to get all barcodes from shop 1 and those from shop 2 even
if there
> is not pair but it doesn't work.

I dont know what I am doing wrong but I never get this "it doesn't
work" error message others seem to get.

Perhaps it is not giving you the results you expect? (Hint: tell us
what results you are getting and what you expect)

Now I am guessing here, I would consider firstly, do you really want
left join? Based on your description,

"to get all barcodes from shop 1 and those from shop 2 even if there
is not pair"

I would have thought a full outer join would have been more
appropriate, or you will not see barcodes in shop 2 for which there is
no equivalent barcode in shop 1, unless this is what you want

12345, 12345
12346, <null>
34234, <null>

Adam