Search code examples
sql-serversql-server-2014

I want to Show Data in Following Manner... by using Single SQL or Procedure


I have two table. Parent and child. I want to make a query to show parent and child data. currently i am using join command to relate both parent and child table. see the attached image where i explained the issue:

Screenshot:

enter image description here


Solution

  • Try this...

    SELECT
        ParentData =  CASE WHEN ROW_NUMBER() OVER (PARTITION BY p.ParentData ORDER BY c.ChildData) = 1 THEN p.ParentData ELSE '' END,
        <other columns>...