CodeIgniter Forums
union all? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: union all? (/showthread.php?tid=19038)



union all? - El Forum - 05-26-2009

[eluser]newbie boy[/eluser]
can anybody help me using union all with tables that has different number of fields...

thanks...


union all? - El Forum - 05-26-2009

[eluser]Phil Sturgeon[/eluser]
You need to get the same number of fields being returned by each statement within the union. That means instead of using * use actual fieldnames and aliases to call them all the same thing.

Code:
( SELECT fieldA as first_thing, fieldB as second_thing FROM table1 )
UNION
( SELECT fieldX as first_thing, fieldY as second_thing FROM table2 )

And no there is no way to handle this with active record ;-)