[Dbix-class] union

Octavian Rasnita orasnita at gmail.com
Fri Apr 27 15:51:16 GMT 2007


From: "Jess Robinson" <castaway at desert-island.me.uk>
>> I have searched for "union" in more POD docs but I couldn't find that 
>> word.
>>
>
>
> You have to cheat a little:
>
>   ->search({},
>            { -order_by => \'col UNION ALL SELECT 1,2,3 FROM othertable' }
>           );
>
> .. just add it in a scalar ref to whichever your last attribute is (last 
> SQL-wise that is)
>
> Jess

Oh, I am not sure what I want to do is really possible. Or maybe I need to 
cheat a little more. :-)

I don't need just a union, but a union that looks like:

select a, b, c, 'var1' as v from table1
where d='value'
union select a, b, c, 'var2' as v from table2
where d='value'
order by a, b desc limit 0,20;

So I will need to put a where condition for each select, and an 'order by' 
at the end.

Is there another trick for doing this, or you think it is possible to put 
the entire SQL string as a value of the "select" parameter, like:

$rs->search({},{
select => \'sql string',
});

Thanks.

Octavian




More information about the Dbix-class mailing list