Subject Re: [firebird-support] Self join
Author Ann W. Harrison
Ann W. Harrison wrote:
>
> SELECT A.barcode, B.barcode
> FROM shops A LEFT JOIN shops B
> ON (A.barcode = > B.barcode A
> AND B.shop_id = 2)
> WHERE A.shop_id = 1;
>

There's an editing mouse turd there - should
be

SELECT A.barcode, B.barcode
FROM shops A LEFT JOIN shops B
ON (A.barcode = > B.barcode
AND B.shop_id = 2)
WHERE A.shop_id = 1;



If you think the ON clause is ugly, you could write the
query like this:


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 or B.shop_id IS NULL);


I doubt there would be any performance difference.


Regards,


Ann