SELECT ntc.newsID, ntc.categoryID, category.title
FROM news_to_category ntc
LEFT JOIN news_category category
ON ntc.categoryID = category.categoryID
WHERE ntc.newsID IN (2,4)
このテーブルで
news_to_category
categoryID newsID
32 2
33 2
23 4
news_category
categoryID title
32 Important
33 Cars
23 Fishing
結果は次のようになります。
Array
(
[2] => Array
(
[0] => Array
(
[0] => 32
[1] => Important
)
[1] => Array
(
[0] => 33
[1] => Cars
)
)
[4] => Array
(
[0] => Array
(
[0] => 23
[1] => Fishing
)
)
)
2番目の配列のキーはnewsIDである必要があります。この結果はたった1つのクエリで可能ですか?どうもありがとう!