Sitecore: SQL query to get item with workflow history with comments.
##More info here: https://medium.com/sitecore-series/sitecore-workflow-history-sql-2e42329ec594
WITH ItemsTable (ItemPath, ID, Name, TemplateID, MasterID, ParentID, Created, Updated)
AS
(
SELECT CAST('/' + base.Name AS nvarchar(MAX)) as ItemPath,
base.ID, base.Name, base.TemplateID, base.MasterID, base.ParentID, base.Created, base.Updated
FROM Items as base
WHERE base.ID = '11111111-1111-1111-1111-111111111111'
UNION ALL
SELECT CAST(ItemPath + '/' + child.Name AS nvarchar(MAX)),
child.ID, child.Name, child.TemplateID, child.MasterID, child.ParentID, child.Created, child.Updated
FROM ItemsTable as parent
INNER JOIN Items as child
ON child.ParentID = parent.ID
)
SELECT ItemsTable.ItemPath, ItemsTable.ID, ItemsTable.Name, ItemsTable.TemplateID, Created, WorkflowHistory.*
FROM ItemsTable
JOIN dbo.WorkflowHistory ON ItemsTable.ID = WorkflowHistory.ItemID