Thread View: comp.databases.mysql
1 messages
1 total messages
Started by Lawrence D’Oliveiro
Thu, 26 Nov 2026 23:41
When To Use “Having” Clauses
Author: Lawrence D’Oliveiro
Date: Thu, 26 Nov 2026 23:41
Date: Thu, 26 Nov 2026 23:41
16 lines
2162 bytes
2162 bytes
Trying to list block_recip entries in order in which they were last
used, including the number of times each one was used, omitting ones
which were never used:
select block_recip.email as email, from_unixtime(max(block_recip_hits.timestamp)) as last, count(*) from block_recip left join block_recip_hits on block_recip.email = block_recip_hits.email where block_recip.enabled = "1" and last is not null group by block_recip.email order by max(block_recip_hits.timestamp);
I get:
ERROR 1054 (42S22): Unknown column 'last' in 'WHERE'
So the “last” column can’t be referenced in a “where”-clause because
it doesnt’ actually exist until after the “group by” takes effect.
But this works:
select block_recip.email as email, from_unixtime(max(block_recip_hits.timestamp)) as last, count(*) from block_recip left join block_recip_hits on block_recip.email = block_recip_hits.email where block_recip.enabled = "1" group by block_recip.email having last is not null order by max(block_recip_hits.timestamp);
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads