diff --git a/migrations/0194.sql b/migrations/0194.sql index 1ca1fd1d..89f0454f 100644 --- a/migrations/0194.sql +++ b/migrations/0194.sql @@ -3,13 +3,14 @@ AS /* Returns stock_id's which have been edited manually */ -SELECT DISTINCT sl_add.stock_id +SELECT sl_add.stock_id FROM stock_log sl_add JOIN stock_log sl_edit ON sl_add.stock_id = sl_edit.stock_id AND sl_edit.transaction_type = 'stock-edit-new' WHERE sl_add.transaction_type IN ('purchase', 'inventory-correction', 'self-production') - AND sl_add.amount > 0; + AND sl_add.amount > 0 +GROUP BY sl_add.stock_id; DROP VIEW stock_average_product_shelf_life; CREATE VIEW stock_average_product_shelf_life diff --git a/migrations/0224.sql b/migrations/0224.sql index 32216e1c..b889fcae 100644 --- a/migrations/0224.sql +++ b/migrations/0224.sql @@ -6,13 +6,16 @@ AS /* Returns stock_id's which have been edited manually */ -SELECT DISTINCT sl_add.stock_id, MAX(sl_edit.id) AS stock_log_id_of_newest_edited_entry +SELECT + sl_add.stock_id, + MAX(sl_edit.id) AS stock_log_id_of_newest_edited_entry FROM stock_log sl_add JOIN stock_log sl_edit ON sl_add.stock_id = sl_edit.stock_id AND sl_edit.transaction_type = 'stock-edit-new' WHERE sl_add.transaction_type IN ('purchase', 'inventory-correction', 'self-production') - AND sl_add.amount > 0; + AND sl_add.amount > 0 +GROUP BY sl_add.stock_id; DROP VIEW products_last_purchased; CREATE VIEW products_last_purchased diff --git a/migrations/0225.sql b/migrations/0225.sql deleted file mode 100644 index b7336b6a..00000000 --- a/migrations/0225.sql +++ /dev/null @@ -1,15 +0,0 @@ -DROP VIEW stock_edited_entries; -CREATE VIEW stock_edited_entries -AS -/* - Returns stock_id's which have been edited manually -*/ -SELECT DISTINCT - IFNULL(sl_add.stock_id, '') AS stock_id, - IFNULL(MAX(sl_edit.id), -1) AS stock_log_id_of_newest_edited_entry -FROM stock_log sl_add -JOIN stock_log sl_edit - ON sl_add.stock_id = sl_edit.stock_id - AND sl_edit.transaction_type = 'stock-edit-new' -WHERE sl_add.transaction_type IN ('purchase', 'inventory-correction', 'self-production') - AND sl_add.amount > 0;