How to get multiple records against one record based on relation?

前端 未结 8 841
遇见更好的自我
遇见更好的自我 2020-11-29 09:11

I have two tables Organisation and Employee having one to many relation i.e one organisation can have multiple employees. Now I want to select all information of a particula

8条回答
  •  北荒
    北荒 (楼主)
    2020-11-29 09:16

    in MS SQL you can do:

    create function dbo.table2list (@input int)
    returns varchar(8000)
    as
    BEGIN
    declare @putout varchar(8000)
    set @putout = ''
    select @putout = @putout + ', ' + 
    from 
    where  = @input
    return @putout
    end
    

    then do:

    select * from org, dbo.table2list(orgid)
    from 
    

    I think you can do it with COALESCE() as well, but can't remember the syntax off the top of my head

提交回复
热议问题