結合された2つのテーブルがあります:
book_types_purchased
ですENUM('paperback','hardcover')
。_ このタイプの行を返したい:
book_title | paperback_date_purchased | hardcover_date_purchased
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'