I have a Products table and Downloads table.
The Downloads table has 4 fields, ID, Name, Category and Download
The Products table has 3 fields specific to Downloads: Downloads, Order Guides and Submittal Sheets. Each one of these fields stores the ID of the record from the Downloads table. There will never be the same Download ID value for these 3 fields in the Product table.
I have the follow SQL statement:
SELECT product_id, product_name, product_download, product_submittal, product_ordering_guide, product_status, tbl_downloads.download_id, tbl_downloads.download_name
FROM tbl_products
LEFT JOIN tbl_downloads ON tbl_products.product_download=tbl_downloads.download_id
LEFT JOIN tbl_downloads ON tbl_products.product_submittal=tbl_downloads.download_id
LEFT JOIN tbl_downloads ON tbl_products.product_order_guide=tbl_downloads.download_id
It generates the following error:
#1066 - Not unique table/alias: 'tbl_downloads'
This error makes sense and I know it was going to happen, but I don’t know how to fix it. I need to add an Alias, but not sure where.
If I remove the last two JOIN statements, everything works as expected.
Thanks
You need to use unique aliases if you are joining the same table multiple times:
For example I used
d1,d2andd3but you might want to be more descriptive in your aliases so it is clear what each join is doing, like this: