How can I use the value from an outer clause inside an inner clause using nested SELECT statements? Eg:
SELECT cost AS c, quantity, (SELECT COUNT(1) FROM accounts WHERE cost = c)
FROM accounts
Can c be referenced in the inner SELECT clause as attempted above?
Alias the outer table (eg.
FROM accounts AS a). Then you can simply doa.costin the inner subquery.EDIT. That being said, there’s a better way to write this query without a sub-query for each row: