I have the following query:

WITH old_replies AS
(
  SELECT email_id, r.message_id, rnk 
  FROM  
  (SELECT  RANK() OVER(PARTITION BY message_id ORDER BY created_at DESC) AS 
rnk, * 
  FROM replies ) AS r
  INNER JOIN emails e
  ON r.message_id = e.message_id
  WHERE rnk != 1
)
 
SELECT * FROM emails 
WHERE message_Id NOT IN (SELECT message_id FROM old_replies) AND id NOT IN 
(SELECT email_id FROM old_repies

Is it in any way possible to create such a CTE as above and then use it to 
filter the results of an existing Sequel model class.

If not, can I execute this as sql and get the results into my model?



-- 
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/d/optout.

Reply via email to