salix/db/versions/.archive/10457-crimsonTulip/00-firstScript.sql

18 lines
403 B
MySQL
Raw Normal View History

USE vn;
CREATE TEMPORARY TABLE tmp.tt
SELECT MIN(id) id, saleFk, workerFk, stateFk
FROM saleTracking
GROUP BY saleFk, workerFk, stateFk
HAVING COUNT(*) > 1;
DELETE st FROM saleTracking st
JOIN tmp.tt USING(saleFk, workerFk, stateFk)
WHERE tt.id <> st.id;
ALTER TABLE saleTracking
ADD CONSTRAINT saleTracking_UN
UNIQUE KEY (saleFk, workerFk, stateFk);
DROP TEMPORARY TABLE tmp.tt;