![]() |
Advanced SQL DELETE syntax currently not supported bij Active Record - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Advanced SQL DELETE syntax currently not supported bij Active Record (/showthread.php?tid=7443) |
Advanced SQL DELETE syntax currently not supported bij Active Record - El Forum - 04-09-2008 [eluser]mycroes[/eluser] My database with company records doesn't allow for multiple changes at the same time by the same person (all fields form the primary key). When merging two companies together I can't just change the company id because that might generate a duplicate record (although it's really quite impossible that someone saved two company records at the same time). The solution is quite simple, I delete from the company with the higher id all the rows that conflict with the company with the lower id. The SQL syntax I was using was this (14 being the low id and 143 being the high id): Code: DELETE FROM company_change AS company1 Code: DELETE company_change AS company1 Code: $this->db->from('company_change AS company1 USING company_change AS company1, company_change AS company2'); Up until now I managed to do about everyhting with the active record class, except for one occassion where I needed to do a subquery and used the db->where with only one argument, which worked nice too. I'd like to do this one with the AR class too, but I'd rather not do it in 2 steps, which seems to be the only option now I think. Anyway, I hope this bit of explanation proves useful to someone else and if someone manages to see another option that I could use then that'd be nice to know too. Regards, Michael |