sql / beginner
Snippet
Counting Total Records Using the COUNT Aggregate Function
The COUNT(*) aggregate function calculates the total number of rows matching a query. The AS keyword assigns a human-readable alias to the resulting aggregate column.
snippet.sql
sql
1
2
SELECT COUNT(*) AS total_ordersFROM orders;
Breakdown
1
SELECT COUNT(*) AS total_orders
Calculates the total count of rows and assigns the result column alias 'total_orders'.
2
FROM orders;
Specifies 'orders' as the target table for the count operation.