39 lines
1.1 KiB
SQL
39 lines
1.1 KiB
SQL
SELECT parent_uuid, uuid, content, notetype, nature, position FROM (
|
|
|
|
WITH RECURSIVE children(
|
|
parent_id,
|
|
parent_uuid, id,
|
|
uuid,
|
|
content,
|
|
notetype,
|
|
creation_date,
|
|
updated_date,
|
|
lastview_date,
|
|
deleted_date,
|
|
cycle
|
|
) AS (
|
|
|
|
SELECT
|
|
notes.id,
|
|
notes.uuid,
|
|
notes.id,
|
|
notes.uuid,
|
|
notes.content,
|
|
notes.notetype, 'page', 0, ','||notes.id||','
|
|
FROM notes INNER JOIN pages
|
|
ON pages.note_id = notes.id
|
|
WHERE pages.id = ?
|
|
AND notes.notetype="page"
|
|
|
|
UNION
|
|
SELECT note_relationships.parent_id, notes.id,
|
|
notes.content, notes.notetype, note_relationships.nature,
|
|
note_relationships.position,
|
|
children.cycle||notes.id||','
|
|
FROM notes
|
|
INNER JOIN note_relationships ON notes.id = note_relationships.note_id
|
|
INNER JOIN children ON note_relationships.parent_id = children.id
|
|
WHERE children.cycle NOT LIKE '%,'||notes.id||',%'
|
|
ORDER BY note_relationships.position)
|
|
SELECT * from children);</code>
|