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

前端 未结 6 659
别那么骄傲
别那么骄傲 2020-12-03 22:10
SELECT * FROM `product` left join category on product.category_id = category.id

This query works fine. But the problem is, both the product table a

6条回答
  •  广开言路
    2020-12-03 22:33

    Use aliases with the AS keyword:

    SELECT p.id AS product_id, p.name AS product_name, c.id AS cat_id, c.name AS cat_name
    FROM `product` AS p
    LEFT JOIN category AS c ON p.category_id = c.id
    

提交回复
热议问题