SQL SELECT from multiple tables + IN LIST

How can I get every article + name of all authors in the article (different from article to another)

Users table :
ID NAME FNAME
1  A    AA
2  B    BB
3  C    CC
4  D    DD

Articles
ID AUTHOR title
1  1,3    ty
2  4      tz

Results
A.id A.title USER1_name USER2_name
1    ty      A          C
2    tz      D          no user

Its working thanks, is there a way to make the one user column instead of two like this :

ID  TITLE NAME
1   ty    A,C
2   yy    B,C,E

because sometimes we have mote than 7 authors :/

Assuming maximum of 2 authors per article

select a.id, a.title, b.u1, b.u2
from articles a
join (
  select if(a.id=b.id,a.id,concat(a.id,',',b.id)) author, a.name u1, if(a.id=b.id,'no user',b.name) u2
  from users a
  join users b) b on a.author = b.author;

demo

Hello, buddy!稿源:Hello, buddy! (源链) | 关于 | 阅读提示

本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 后端存储 » SQL SELECT from multiple tables + IN LIST

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录