Right now I got a structure that outputs exactly the result I'm looking for, however I think it isn't as optimized as I would like to since it runs the same table twice (crafted_table). Here's the structure of my query:
SELECT *
FROM (crafted_table) c
RIGHT JOIN
(
SELECT * FROM
(
SELECT DISTINCT a.var1
FROM (crafted_table) a
)
CROSS JOIN (time_table)
) b
ON c.var1 = b.var1
Is there a way to run this same query without running crafted_table twice? (crafted_table is a table made by me from other tables). I was thinking something about running the most inner case and just reference it in the most outer case, but not quite sure how to achieve it.
Thanks!