I have a table
id|level|name
Levelmaybe 1,2 or 3
what i want to get:
id|lvl1name|lvl2name|lvl3name
I am using the following query
SELECT L1."name" as lvl1name, L2."name" as lvl2name, L3."name" as
lvl3name, L1.id
FROM table as L1
JOIN table as L2 ON L1.id = L2.id
JOIN table as L3 ON L2.id = L3.id
WHERE L1.lvl='1' and L2.lvl='2' and L3.lvl='3';
but he is slow slow!
There must be a better way to do this. please, help
for this example, I am using postgres, but I would be glad to know that it does not depend on the database function.
I cannot write procedures (read-only access) and I select this from the view.
source
share