Hello,

How can I use WITH and UNION ALL in single query? I'm trying to do this query:

WITH united as (
  SELECT email, full_name FROM contacts
  UNION ALL
  SELECT sender->>'email', sender->>'name' FROM emails
)

SELECT
  email,
  full_name,
  count(*) count,
  row_number() over (partition by email) rk

FROM united
GROUP BY 1, 2;

How can i write this in Sequel?

What I've tried so far (and failed) something like:

Contact.from { united.as(:s) }
.select_all(:s) .where { s[:rk] =~ 1 } 
.with(:summary_senders, Email.from { emails.as(:d) }
.where(name: "john")
.union(Contact.from { contacts.as(:d2) })).order(Sequel.desc(:count)).sql




Thanks,

Dennis

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sequel-talk/ee4ca5a6-391b-4a01-9806-5df9fcf55926%40googlegroups.com.

Reply via email to