Имя пользователя:
Пароль:  
Помощь | Регистрация | Забыли пароль?  

Название темы: COUNT(*)
Показать сообщение отдельно

Аватара для vadimiron

Ветеран


Сообщения: 1864
Благодарности: 120

Профиль | Отправить PM | Цитировать


slaine
Речь идёт о MySQL
Насколько я понимаю, то нельзя
Почитайте тут , в комментарии к этой статье написано
Цитата:
If you are using SELECT DISTINCT on a complex join clause, you might be stumped to find the count without returning the whole recordset. For example:

SELECT DISTINCT COUNT(*) AS theCount FROM table1, table2 WHERE table1.user_id = table2.user_id

Will not return the same number for 'theCount' as you would have using mysql_num_rows and:

SELECT DISTINCT table1.user_id FROM table1, table2 WHERE table1.user_id = table2.user_id

This is because DISTINCT affects the user_id, not the count. If you try something like:

SELECT DISTINCT table1.user_id, COUNT(*) AS theCount FROM table1, table2 WHERE table1.user_id = table2.user_id

Then you'll get an error saying there's no GROUP BY clause. The key is to collapse all of the rows using GROUP BY NULL:

SELECT DISTINCT table1.user_id, COUNT(*) AS theCount FROM table1, table2 WHERE table1.user_id = table2.user_id GROUP BY NULL

-------
Fortes fortuna adiuvat


Отправлено: 00:04, 21-08-2005 | #5

Название темы: COUNT(*)