MySQL: Left join and column with the same name in different tables
mysql
Solution
You can add aliases to the fields:
SELECT
a.id,
a.name,
a.category_id,
b.id AS catId,
b.name AS catName
FROM
product AS a
LEFT JOIN
category AS b ON a.category_id = b.category.id
Problem
Consider: ``` SELECT * FROM `product` left join category on product.category_id = 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?