I'm trying to query a SQLite database, I have the following tables:
Table suggestions:
CREATE TABLE IF NOT EXISTS sugestoes (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
texto VARCHAR(250),
autor VARCHAR(250),
itens VARCHAR(250),
pontos INTEGER
);
Vertices table
CREATE TABLE IF NOT EXISTS vertices (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
id_node_pai INTEGER,
id_node_filho INTEGER,
FOREIGN KEY (id_node_pai) REFERENCES sugestoes(id),
FOREIGN KEY (id_node_filho) REFERENCES sugestoes(id)
);
Within them I have the following data:
Iwouldliketogetthefollowingoutput:
I've made the following query:
WITH vertices AS (
SELECT p.autor FROM sugestoes p, vertices e
WHERE e.id_node_pai = p.id
UNION ALL
SELECT f.autor FROM sugestoes f
INNER JOIN vertices d
ON f.id = d.id_node_filho
)
SELECT * FROM vertices;
However I have gotten the following error:
Error: circular reference: vertices
I tried to use WITH RECURSIVE
, but without success too.