· 9 years ago · Oct 01, 2016, 11:58 AM
1DELETE FROM mappings AS m
2WHERE EXISTS ( SELECT 1
3 FROM code_mappings AS cm
4 INNER JOIN codes AS c
5 ON c.remote_id = cm.code_remote_id
6 WHERE
7 (
8 c.company_id NOT IN (6, 753, 785, 1611)
9 AND cm.id = m.id
10 )
11)
12
13CREATE INDEX company_id_idx ON appointments (company_id);
14
15CREATE INDEX remote_id_company_id_idx ON codes (remote_id, company_id);
16
17CREATE INDEX code_remote_id_id_idx ON code_mappings (code_remote_id, id);
18
19-- If you don't already have a primary key OR index on `id` column in the `mappings` table, then create one:
20
21ALTER TABLE mappings ADD PRIMARY KEY (id);
22-- Choose primary key, or index: CREATE INDEX id_idx ON mappings (id);