[英]Combining the many side of a many-to-one relationship into one field?
兩個表: books
和authors
。 一本書可以有很多作者,就像短篇小說選集一樣。
id | title
--------------------
1 The Time Machine Did It
2 Snakes in Suits
3 Ghost in the Wires
id | name
------------------------
1 Stephen King
2 John Swartzwelder
3 Robert D. Hare
4 Kevin Mitnick
5 William L. Simon
6 Steve Wozniak
7 Paul Babiak
book_id | authors_id
---------------------------
1 2
2 3
2 7
3 4
3 5
3 6
我想做的是返回一個表,其中每一行都是一本書,'authors'字段是所有作者的逗號分隔列表,例如
title | authors
---------------------------------
The Time Machine Did It John Swartzwelder
Snakes in Suits Robert D. Hare, Paul Babiak
Ghost in the Wires Kevin Mitnick, William L. Simon, Steve Wozniak
我一直在玩GROUP BY
和連接函數,我知道答案就在那里,但我無法弄明白。 我可以通過在程序本身中處理數組和字符串連接來實現它,但這不是我正在尋找的優雅解決方案。 這里的提示將不勝感激。
我正在使用SQLite 3,如果它是依賴於系統的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.