Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select all columns, and a count(*) in the same query

Tags:

sql

oracle

In often use in TSQL the following query :

SELECT COUNT(*), *  FROM CUSTOMER c  WHERE c.Name like 'foo%'; 

When I try to execute this query in Oracle SQL Developer it doesn't work and throws me an error:

"Missing expression"

What is the good syntax ?

Thanks in advance.

like image 211
Etienne Arthur Avatar asked Jun 19 '13 09:06

Etienne Arthur


People also ask

How do I select all and count columns in SQL?

SELECT COUNT(column_name) FROM table_name; The SELECT statement in SQL tells the computer to get data from the table. COUNT(column_name) will not include NULL values as part of the count. A NULL value in SQL is referring to values that are not present in the table.

Are count (*) and count () the same function?

Since it doesn't matter which value you put in the parentheses, it follows that COUNT(*) and COUNT(1) are precisely the same. They are precisely the same because the value in the COUNT() parentheses serves only to tell the query what it will count.


1 Answers

This will perform better:

SELECT COUNT(*) OVER (), c.* FROM CUSTOMER c  WHERE c.Name like 'foo%'; 
like image 134
Jeffrey Kemp Avatar answered Sep 23 '22 15:09

Jeffrey Kemp