sql server - Select multiple value using subquery -
i have 3 tables:
articles
articletags
article_articletags_rel
articletags_rel table has 2 columns
articleid_fk
tagid_fk
as can see article_articletags_rel make relation between articles , articletags
all want select 1 row articles table , and related tags (multiple values) using sub-query.
how can achieve this?
you can try this:
select a.name, b.tagname article_articletags_rel c inner join articles on a.id = c.articleid_fk left outer join articletags b on b.id = c.tagid_fk
result:
name tagname --------------- art tag 1 art tag 2 art tag 3 art b tag 1 art b tag 3 art c tag 1 art c tag 3
sql fiddle: http://sqlfiddle.com/#!6/8d30f/2
Comments
Post a Comment