On Monday, August 5, 2013 8:28:58 PM UTC-7, Brenton Annan wrote:
>
> I hit post before I was finished. Apologies all. The query I was writing
> was something along the lines of:
>
> SELECT a.x, b.y FROM table_a a, table_b b WHERE (SELECT MAX(b.y) WHERE b.x
> = a.x);
>
> Some advice on how to go about doing something like this with Sequel, or a
> link to appropriate docs would be appreciated.
>
I don't understand your WHERE condition. It doesn't return a boolean
value, and the max calculation in the subquery is unrelated to the
selection in the outer query. Are you sure that's the SQL you want to
generate?
Assuming you actually want something like:
SELECT a.x, max(b.y) FROM table_a AS a, table_b AS b WHERE (b.x = a.x)
You could use:
DB.from(:table_a___a, :table_b___b).
select(:a__x){max(:b__y)}.
where(:b__x=>:a__x)
Thanks,
Jeremy
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/groups/opt_out.