我有两个表连接在一起:
book_types_purchased
是ENUM('paperback','hardcover')
。_ 我想返回这种类型的行:
书名 | 平装书_购买日期 | 精装日期购买
有没有办法在 MySQL 中做到这一点?
更新
以下是匹配表名和左连接的答案:
SELECT title,
paperback.date_purchased AS paperback_date_purchased,
hardcover.date_purchased AS hardcover_date_purchased
FROM book_projects
LEFT JOIN book_types_purchased AS paperback
ON paperback.book_project_id = book_projects.id
AND paperback.type = 'paperback'
LEFT JOIN book_types_purchased AS hardcover
ON hardcover.book_project_id = book_projects.id
AND hardcover.type = 'hardcover'