When I run the following query, I would like to include a field that returns the COUNT of the number of records in the sub query. The sub query however has a WHERE clause where a field in this clause must match a field in the parent query's SELECT statement:
SELECT id, firstName, lastName,
COUNT(
SELECT userId, address FROM UserDetails WHERE userId = <id_from_outer_select_statement>
)
FROM Users
It isn't clear to me how to apply the id field from the outer SELECT statement to the sub query.