I want to modify the following query from a model on Codeigniter:
public $table = 'fi_client_notes';
public $primary_key = 'fi_client_notes.client_note_id';
public function default_select()
{
$this->db->select("SQL_CALC_FOUND_ROWS fi_client_notes.*, fi_clients.client_name", FALSE);
if ($this->session->userdata('user_id') <> 1)
{
$this->db->where('fi_clients.user_id', $this->session->userdata('user_id'));
}
}
public function default_order_by()
{
$this->db->order_by('fi_client_notes.client_note_date DESC');
}
public function default_join()
{
$this->db->join('fi_clients', 'fi_clients.client_id = fi_client_notes.client_id');
}
My goal is to select first only the rows where the value "fi_client_notes.client_note_end" is equal to today's date, then show all the rest of the rows arranged in descending order based on the value "fi_client_notes.client_note_date".
This is the query I'm trying:
(SELECT SQL_CALC_FOUND_ROWS fi_clients.client_name, fi_client_notes.* FROM (`fi_client_notes`) JOIN `fi_clients` ON `fi_clients`.`client_id` = `fi_client_notes`.`client_id` WHERE `fi_client_notes`.`client_note_end` = CURDATE())
UNION
(SELECT fi_clients.client_name, fi_client_notes.* FROM (`fi_client_notes`) JOIN `fi_clients` ON `fi_clients`.`client_id` = `fi_client_notes`.`client_id`
ORDER BY `fi_client_notes`.`client_note_date` DESC LIMIT 15)
But I don't know how to use it on Codeigniter, since CodeIgniter's ActiveRecord doesn't support UNION