I am trying to get row count from the following query. I get only row count as 1 but there are 35 records. Could you please let me know how to get the count from inner query?
Thank you
SELECT COUNT(*)(SELECT DISTINCT a.my_id, a.last_name, a.first_name, b.temp_val FROM Table_A a INNER JOIN Table_B b on a.a_id = b.a_id)
SQL SELECT COUNT(*) function The COUNT(*) function represents the count of all rows present in the table (including the NULL and NON-NULL values).
SELECT COUNT(*) FROM table_name; The COUNT(*) function will return the total number of items in that group including NULL values. The FROM clause in SQL specifies which table we want to list. You can also use the ALL keyword in the COUNT function.
Syntax of Select Count Function in SQL In the syntax, we have to specify the column's name after the COUNT keyword and the name of the table on which the Count function is to be executed.
The SQL COUNT() function returns the number of rows in a table satisfying the criteria specified in the WHERE clause. It sets the number of rows or non NULL column values. COUNT() returns 0 if there were no matching rows.
You're missing a FROM and you need to give the subquery an alias.
SELECT COUNT(*) FROM ( SELECT DISTINCT a.my_id, a.last_name, a.first_name, b.temp_val FROM dbo.Table_A AS a INNER JOIN dbo.Table_B AS b ON a.a_id = b.a_id ) AS subquery;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With