0
JOIN我現在有這個疑問設置:MYSQL在同一臺
SELECT
topic.content_id,
topic.title,
image.location
FROM
mps_contents AS topic
INNER JOIN mps_contents AS image
ON topic.content_id = image.page_id
WHERE
topic.page_id = (SELECT page_id FROM mps_pages WHERE page_short_name = 'foo')
AND image.display_order = '1'
這是因爲我想在一列從同一個表合併兩行。這是表
-----------------------------------------------------------
| page_id | content_id | title | location | display_order |
-----------------------------------------------------------
| 1 | 200 | Foo | NULL | 200 |
| 1 | 201 | Baz | NULL | 201 |
| 200 | 201 | Bar | jpg.jpg | 1 |
-----------------------------------------------------------
And basically I want this result
---------------------------------
| content_id | title | location |
---------------------------------
| 200 | Foo | jpg.jpg |
| 201 | Baz | NULL |
---------------------------------
基本上我想選擇所有主題的簡化設置,那麼也會返回如果有相應的圖像。我當前的查詢只返回所有與關聯圖像相關的主題。我嘗試了左和右外連接,但它似乎沒有幫助。
您的查詢看起來不錯,你試過沒有where子句? (它包含你沒有在你的簡化設置中指定的列) – Jacob