vBulletin Search Engine Optimization
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| How do I get the results of a SELECT, and count the results at the same time? I've tried: SELECT productname, COUNT(*) AS cnt from URL but this gives: Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause Help! |
| |||
| lister schrieb: > How do I get the results of a SELECT, and count the results at the > same time? > > I've tried: > > SELECT productname, COUNT(*) AS cnt from URL > > but this gives: > Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP > columns is illegal if there is no GROUP BY clause You need to add a "group by " to your statement (like the error message tells you). |
| |||
| lister wrote: >> You need to add a "group by " to your statement (like the error message >> tells you). > > But I don't want it grouped by anything. I just want the normal result > set. > > that will be the normal result set. for mysql to calculate the count it needs to group by the column you're selecting so something like this will do it for you: SELECT productname, COUNT(*) AS cnt from URL group by productname -- lark -- hamzee@sbcdeglobalspam.net To reply to me directly, delete "despam". |
| ||||
| On May 3, 3:20 am, lister <listerofsme...@hotmail.com> wrote: > How do I get the results of a SELECT, and count the results at the > same time? > Can't do it in one command. Mysql has a command that lets you get the number of results served in the last query, but I don't remember what it is. Your programming language of choice might offer up an easy way to accomplish what you're after though. Aerik |