Here the id column is some column that identifies the row. It could be the foo column or some other column or even a collection of columns. Whatever it is, just put it in the SELECT phrase in addition to the GROUP BY phrase, e.g. if your rows in tablea are identified by the columns id1 and id2, then use:SELECT tablea.id, COUNT(*) FROM tablea, tableb WHERE tablea.foo = tableb.bar GROUP BY tablea.id
The sub-select approach will work, but databases have a lot of techniques for efficiently executing GROUP BY queries. With the sub-select approach you run the risk of explicitly telling the database how to run the query which doesn't allow it to optimize it.SELECT tablea.id1, tablea.id2, COUNT(*) FROM ... ... GROUP BY id1, id2
In reply to Re: perl dbi select question - using GROUP BY
by pc88mxer
in thread perl dbi select question
by baxy77bax
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |