user1091856 user1091856 - 6 months ago 27
MySQL Question

MySQL: Left join and column with the same name in different tables?

SELECT * FROM `product` left join category on product.category_id =

This query works fine. But the problem is, both the product table and the category table have fields named "name" and "id". So when I fetch the result of this query, it gives me only one name and one id, but I want both id's and name's.

How can I do this without having to rename the fields?
Is it possible to return with custom names such as product_name and category_name?


you can give the fields aliases

SELECT,, a.category_id, AS catId, AS catName
FROM product AS a left join category AS b on a.category_id =