WebOct 7, 2024 · var query = (from p in appList join q in userAppList on p.ParentId equals q.UserAppId select new { ParentName = appList.Where (c => c.AppId == p.ParentId).FirstOrDefault ().AppName, AppName = p.AppName }).ToList (); WebSELECT t2.id, t2.[Name], t2.ParentID,M.[level] + 1 AS [Level], CAST( (M.Hierarchy + '->' + t2.Name) AS VARCHAR(MAX)) AS Hierarchy FROM #tbHierarchy AS t2 JOIN MyCTE AS M ON t2.ParentId = M.Id ) SELECT * FROM MyCTE Explanation: The base record for the CTE is obtained by the first select query above UNION ALL.
sql - Display Parent-Child relationship when Parent and Child are ...
WebApr 1, 2024 · In this article I will explain how to write a query to create parent-child hierarchy ( Continent-> Country-> State-> City ) with levels using recursive common table expression (CTE). While working with database we often store parent and child id in same table. Let's take the example of Continents, Countries, State/Province and City. WebSep 21, 2024 · SELECT 4, 2 from dual union all. SELECT 5, 2 from dual union all. SELECT 6, 5 from dual) SELECT * FROM hier; The query output: I want to produce the output as sys_connect_by_path does, but in a row-centric way as shown below: So every node_id in the output has complete hierarch in hier_node_id column as set of rows. small print shop equipment
SQL Server: How To Extract Parent Child Relation From XML
WebFeb 8, 2024 · WITH Recursives AS ( SELECT CAST (ID AS VARCHAR (MAX)) + '\' ID,* FROM table WHERE id=@ID UNION ALL SELECT r.ID + CAST (t.ID AS VARCHAR (MAX)) + '\', t.* FROM table t INNER JOIN Recursives r ON t.parentID= r.ID) SELECT ID,Name,Parent FROM Recursives r I use this to get a list for a specific parent all the way down. WebSep 12, 2024 · SELECT DISTINCT parent FROM "table_name" t1 WHERE parent IS NOT NULL; Get all the single records (only records does not come under parent-child) Example: 5,6,7 SELECT DISTINCT id FROM "table_name" t1 WHERE t1.id= t1.parent IS NULL; Share Improve this answer Follow answered Jun 8, 2024 at 8:55 Lokesh Reddy 29 7 Add a comment Your … small print shop management software