如果JOIN categories c ON c.id = i.category
为1,我希望使用post_type
我希望c.title AS category_name,
中SELECT
JOIN categories c ON c.id = i.category
,c.title AS category_name,
和post_type
必须没有在查询中工作,我使用case加入但我的sql命令不正确。请帮我。在所有描述中,我的quastion意味着如何更改以下命令,如果SELECT SQL_CALC_FOUND_ROWS
i. * ,
c.title AS category_name,
s.title AS status_title,
i.thumb_image,
CONCAT( u.name, ' ', u.family ) AS author
FROM contents i
LEFT JOIN categories c
ON i.category = CASE post_type WHEN 1 then c.id END
JOIN users u ON u.id = i.posted_by
JOIN status_topics s ON s.id = i.t_status
WHERE i.id = 2
是1加入必须不起作用
{{1}}
答案 0 :(得分:0)
我会一直做LEFT JOIN
并在列本身上加上一个条件:
SELECT SQL_CALC_FOUND_ROWS
i. * ,
IF(i.post_type = 1, c.title, NULL) AS category_name,
s.title AS status_title,
i.thumb_image,
CONCAT( u.name, ' ', u.family ) AS author
FROM contents i
LEFT JOIN categories c ON i.category = c.id
JOIN users u ON u.id = i.posted_by
JOIN status_topics s ON s.id = i.t_status
WHERE i.id = 2