CREATE VIEW product_barcodes_view AS SELECT pb.id, pb.product_id, pb.barcode, pb.qu_id, pb.amount, pb.shopping_location_id, pb.last_price, pb.note FROM product_barcodes pb UNION ALL -- Product Grocycodes SELECT p.id, p.id AS product_id, 'grcy:p:' || CAST(p.id AS TEXT) AS barcode, p.qu_id_stock AS qu_id, NULL AS amount, NULL AS shopping_location_id, NULL AS last_price, NULL AS note FROM products p;