的3類不同的表我有3個表加入基於崗位
職位(含每一個崗位類型)
ID | type | PostID | timestamp
1 | 1 | 1 | 1378561301
2 | 2 | 1 | 1378561302
3 | 1 | 2 | 1378561303
4 | 2 | 2 | 1378561304
posts_messages
ID | message
1 | CAT
2 | RAT
posts_photos
ID | photo | caption
1 | ant.jpg | Ant
2 | orange.jpg | Orange
我想得到th Ë導致這樣
結果:
ID | Type | PostID | timestamp | message | photo | caption
1 | 1 | 1 | 1378561301 | CAT | null | null
2 | 2 | 1 | 1378561302 | null | ant.jpg | Ant
3 | 1 | 2 | 1378561303 | RAT | null | null
4 | 2 | 2 | 1378561304 | null | orange.jpg | Orange
我已經試過是UNION,但它不是完整的。任何建議/替代查詢?
所以ID在posts_messages和posts_photos是一個從帖子ID? –
sqlfiddle或您的查詢是必要的。 –
@AbhikChakraborty是的 –