CodeIgniter Forums

Full Version: union all?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

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


El Forum

[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.

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

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