Hello,

I ran into this issue with Sequel and MariaDB/MySQL, with a query that uses
Dataset#select_append to get some calculated values and then uses
Dataset#having to filter by those calculated fields. This produces a MySQL
syntax error, as Dataset#count ensures that COUNT is the only thing in the
select clause, and thus makes the HAVING clause fail. The error can be seen
here: https://gist.github.com/sjweil9/4b327714ea2900a5348985d3c044bc58.

I suspect that there is probably a better way to go about this (from an SQL
perspective), but for MySQL at least I believe it is technically valid to
use HAVING without a GROUP BY to allow referencing the SELECT alias field.
It may just be fair that the Dataset#count is properly optimized to remove
other fields from the SELECT clause and thus should not be used with a
having clause, and that I should resort to something like the alternative
in the gist (using the subquery in a FROM clause and counting that). Is
this the expected behavior or is there a better way for me to approach this?

Thank you for your help as always!

Best,

Stephen

-- 
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 https://groups.google.com/group/sequel-talk.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sequel-talk/CANba2HMW9egECFQSFay05_oTztkcYi20NJws8tVk6bZ%3DHzJ7fw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to