所以我确实有2个这样的表:
____________________________________________________
|categories_id|categories_name|categories_description|
和
__________________________________________
|categories_id|img_link|parent_id|
和其他一些不相关的列 我希望以这种方式展示:
id|categories_name|parent_id|img_link
这是我到目前为止所提出的......
SELECT '' as 'id', c.categories_id, cd.categories_name as 'Name', c.parent_id as 'Parent Category', concat('http://www.url.com/images/',c.categories_image) as 'Image URL'
FROM categories c, categories_description cd
WHERE c.categories_id=cd.categories_id
GROUP BY c.categories_id;
这让我有了这样的事情:
id|categories_name|parent_id|img_link
我试图以某种方式离开加入,但没有成功。
SELECT c.categories_id, '' AS 'id', cd.categories_name AS 'Name', c.parent_id AS 'Parent Category', concat('http://www.url.com/images/',c.categories_image) AS 'Image URL'
FROM categories_description cd
LEFT JOIN categories c ON c.parent_id = cd.categories_name
WHERE c.categories_id=cd.categories_id AND language_id=1
GROUP BY c.categories_id;
这将在“父类别”列中返回零。问题是,如何将此parent_id
替换为categories_name
parent_id=categories_id
...
答案 0 :(得分:0)
在第二个查询中,您将加入c.parent_id = cd.category_name而不是c.parent_id = cd.parent_id。