MySQL - Doing COUNT (*) for the current row
Here's my request SELECT
:
SELECT col1, col3, col5, col8
FROM Table1
In my query, SELECT
I want to do COUNT (*) exclusively on the current row .
I want something like this, but have no idea how I can do this:
SELECT col1, col3,
(
SELECT COUNT(*)
FROM table1 WHERE col3 = col3 value for current row
),
col5, col8
FROM Table1
What is the correct way to do COUNT (*) on the current row of the query result set SELECT
?
source to share
Found.
If I write my request like this:
SELECT col1, col3,
COUNT(*) AS count,
col5, col8
FROM Table1
then i get the COUNT of all items in table1 for all rows.
I really need COUNT for all items for selectable rows.
Like mine, col3 value appears more than once. I really want to count all elements for each col3.
So the proposal GROUP BY
is the solution.
SELECT col1, col3,
COUNT(*) AS Count,
col5, col8
FROM Table1
GROUP BY col3
Sorry, it seems to me that I was not able to explain my problem correctly, so it confused a lot of people. A very bad question. I'm sorry.
source to share