I'm attempting to convert a moderately complex query:

SELECT a1.* FROM activities a1
INNER JOIN activities_channelships cs ON cs.channel_id = a1.channel_id
LEFT JOIN activities a2
ON a1.channel_id = a2.channel_id AND a1.created_at < a2.created_at
WHERE a2.id IS NULL
AND cs.user_id = 1
ORDER BY a1.created_at DESC;

I have Sequel::Model setup for all of the tables, columns involved yet I 
get stumped pretty early on when trying to convert this over and looking at 
Sequels raw SQL output, here's what I have so far:

Activity.join(ActivityChannelship, channel_id: 
:channel_id).left_join(Activity, channel_id: :channel_id).sql

Problem being is the left_join emits another "activities" table select that 
conflicts with the first one. I'm not extremely robust in Sequel yet when 
moving to complex queries so I scoured the docs but wasn't able to find 
anything that may treat it more like the query above.

Any help anyone may have in converting this query would be much 
appreciative.

-Robert

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

Reply via email to