Your solution is UNION. Since you are fetching data from 3 different table that has no relations between them, so better to use UNION
. Also codeigniter's active record
doesn't support UNION
, so you have to write the whole sql query. Check this out -
$sql = "(SELECT colA, colB, pubdate as dt FROM articles) UNION
(SELECT colM, colN, pubdate as dt FROM link_posts) UNION
(SELECT colX, colZ, pubdate as dt FROM image_posts)
ORDER BY dt DESC
";
$query = $this->db->query($sql);