0

私はそのような2つのテーブルを持っています:

Item
-------------------------------------
|ID | ImageURLID | BannerImageURLID |
-------------------------------------
| 1 |     1      |        2         |
| 2 |     3      |        4         |
| 3 |     5      |        6         |
-------------------------------------

ImageURL
--------------------------------------
|ID |   iOSURL    |   iOSRetinaURL   |
--------------------------------------
| 1 | www.test.at |   www.testR.at   |
| 2 | www.bann.at |   www.bannR.at   |
| 3 | www.test.at |   www.testR.at   |
| 4 | www.bann.at |   www.bannR.at   |
| 5 | www.test.at |   www.testR.at   |
| 6 | www.bann.at |   www.bannR.at   |
--------------------------------------

そして、出力を次のようにしたい:

-------------------------------------------------------------------------------------
|ID | ImageURLiOS | ImageURLiOSRetina | BannerImageURLiOS | BannerImageURLiOSRetina |
-------------------------------------------------------------------------------------
| 1 | www.test.at |   www.testR.at   |    www.bann.at     |      www.bannR.at       | 
| 2 | www.test.at |   www.testR.at   |    www.bann.at     |      www.bannR.at       | 
| 3 | www.test.at |   www.testR.at   |    www.bann.at     |      www.bannR.at       | 
-------------------------------------------------------------------------------------

グループ化と内部結合をいくつか試しましたが、実際には何も機能しません。SQLでそれを達成することは可能ですか、それともPHP処理を行う必要がありますか?

4

1 に答える 1

2
select i.id, 
       u.iOSURL as ImageURLiOS,
       u.iOSRetinaURL as ImageURLiOSRetina, 
       ur.iOSURL as BannerImageURLiOS,
       ur.iOSRetinaURL as BannerImageURLiOSRetina 
from item i 
left join imageurl u on u.id = i.imageurlid
left join imageurl ur on ur.id = i.bannerimageurlid
于 2013-10-19T10:50:29.777 に答える