Why this query return with error of duplicate id? I’m using php
SELECT DISTINCT * FROM products as prd
LEFT OUTER JOIN (SELECT DISTINCT * FROM product_aliases) AS product_aliases
ON product_aliases.product_id = prd.id
AND product_aliases.alias = '$alias'
LEFT OUTER JOIN (SELECT DISTINCT * FROM product_images as prdim
LEFT OUTER JOIN product_image_votes as prdimvt
ON prdimvt.product_image_id = prdim.id) AS productimages
ON productimages.product_id = prd.id
WHERE prd.id = $id
ERROR:
Database Error Error: SQLSTATE[42S21]: Column already exists: 1060
Duplicate column name ‘id’ SQL Query: SELECT DISTINCT * FROM products
as prd LEFT OUTER JOIN (SELECT DISTINCT * FROM product_aliases) AS
product_aliases ON product_aliases.product_id = prd.id AND
product_aliases.alias = ‘Pringles The Original’ LEFT OUTER JOIN
(SELECT DISTINCT * FROM product_images as prdim LEFT OUTER JOIN
product_image_votes as prdimvt ON prdimvt.product_image_id = prdim.id)
AS productimages ON productimages.product_id = prd.id WHERE prd.id = 1
You have 3 tables in your query and it is possible at least 2 of them have the same column
id. Using*in your select would select all columns in these three tables selectingidmultiple timesYou could solve this by specifying the columns using the alias
You could also do
if you don’t want to list them one by one