我想使用JOIN categories c ON c.id = i.category
if post_type
is 1 并且我想c.title AS category_name,
在SELECT
其他情况下使用JOIN categories c ON c.id = i.category
并且c.title AS category_name,
不能在查询中工作,我使用 case 进行连接,但我的 sql 命令不正确。请帮我。在所有描述中,我的问题是如何将以下命令更改为 if post_type
is 1 join must not work
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