database query combine possibility - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=11) +--- Thread: database query combine possibility (/showthread.php?tid=68474) |
database query combine possibility - eagle00789 - 07-16-2017 i currently have to following 2 query's: Code: SELECT `PersonelID` FROM `vacations` WHERE ( `FromDate` <= '2017-07-10' OR ( `FromDate` BETWEEN '2017-07-10' AND '2017-07-16' ) ) AND ( `ToDate` >= '2017-07-16' OR ( `ToDate` BETWEEN '2017-07-10' AND '2017-07-16' ) ) Code: SELECT `PersonelID`, `FirstName`, `LastName` FROM `personel` WHERE `PersonelID` NOT IN('3') AND `Active` = 1 ORDER BY `FirstName` ASC Code: SELECT `PersonelID`, `FirstName`, `LastName` FROM `personel` WHERE `PersonelID` NOT IN(SELECT `PersonelID` FROM `vacations` WHERE ( `FromDate` <= '2017-07-01' OR ( `FromDate` BETWEEN '2017-07-01' AND '2017-07-02' ) ) AND ( `ToDate` >= '2017-07-02' OR ( `ToDate` BETWEEN '2017-07-01' AND '2017-07-02' ) )) AND `Active` = 1 ORDER BY `FirstName` ASC PHP Code: $this->db->select('PersonelID')->from('vacations'); RE: database query combine possibility - PaulD - 07-16-2017 Hi, Since you have already written the sql why not just use it like so: PHP Code: $this->db->query('YOUR QUERY HERE'); For complex queries it is often easier to write an sql query and use is as above. In the docs: https://www.codeigniter.com/user_guide/database/queries.html#queries Best wishes, Paul. PS You can also enable the profiler to view the query that was generated which often shows you where it is going wrong. PHP Code: $this->output->enable_profiler(TRUE); |