CREATE OR REPLACE VIEW my_schema.my_table as
SELECT
t.integer_id_column,
t.col2,
COALESCE(r.col1, r.col2) AS ID,
r.col1,
t.col3,
t.col4,
r.col2
FROM table1 t
LEFT JOIN table2 qr ON t.integer_id_column = qr.integer_id_column
LEFT JOIN table3 r ON r.integer_quantity = t.integer_quantity AND r.date = t.date
WHERE t.type = 'my_type' AND (t.cost = 0 or t.cost IS NULL)
ORDER BY 1 DESC;
I’m working with a postgresql database, and I see the above table created. I don’t see any point in the left join on table2
since the select
statement doesn’t actaully select anything from table2
. Is there some reason that this would be done in postgresql that I’m not aware of?