我有這個查詢。子查詢只返回一個值
SELECT
d.gid, d.channel_id
FROM channels, (
SELECT
gigs.id as gid, gigs.channel_id
FROM gigs
ORDER BY gigs.id DESC
LIMIT 1
) as d
WHERE d.channel_id = channels.id
LIMIT 10
我希望得到每個channels.id
一個gid
,而是它只返回一列。這是爲什麼?
演出表
+---------+------------+
| id | channel_id |
+---------+------------+
| 150661 | 6 |
| 745797 | 6 |
| 483996 | 6 |
| 3407209 | 6 |
| 1175022 | 5 |
| 3238459 | 6 |
| 711413 | 5 |
| 524758 | 5 |
| 154764 | 5 |
| 1594779 | 5 |
| 1659091 | 2 |
| 1086768 | 6 |
| 1161320 | 8 |
| 467394 | 5 |
| 2877040 | 8 |
| 2705821 | 6 |
| 1881747 | 5 |
| 901902 | 1 |
| 143322 | 6 |
| 671658 | 1 |
+---------+------------+
頻道表
+----+
| id |
+----+
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
| 6 |
| 7 |
| 8 |
| 9 |
| 10 |
+----+
你能提供你問題的樣本記錄嗎? :D –
當然。我添加了一個更簡單的查詢和一些示例數據 – Oleander
查看我更新的答案。 –