database query combine possibility |
07-16-2017, 12:19 PM
(This post was last modified: 07-16-2017, 12:20 PM by eagle00789. Edit Reason: typo fix )
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');
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/d...ml#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); |
Welcome Guest, Not a member yet? Register Sign In |