count subquery code example

Example: count subquery sql

/*count sub query
Depends on the use case, here are a few options*/

Select Count(*) from 
(
--Sub query
Select id from users 
) as userCount

Select * from 
(
--Sub query
select count(id) as cnt from Users where LastPasswordChangedDate < '2021-01-01'
) as LastPasswordChangedDate

Select 
(
	--Sub query
	select count(id) as cnt from Users where LastPasswordChangedDate < '2021-01-01'
) as LastPasswordChangedDateCount
, *
from Users
where LastPasswordChangedDate < '2021-01-01'

Tags:

Sql Example