Is there a way to popullate a column based on another column.
For example
SELECT name, age, (select count(*) FROM ORDERS WHERE name = **value in column [name]**) FROM PEOPLE
Any help is greatly appreciated.
Is there a way to popullate a column based on another column.
For example
SELECT name, age, (select count(*) FROM ORDERS WHERE name = **value in column [name]**) FROM PEOPLE
Any help is greatly appreciated.
You can but you have to use proper aliases for the tables:
SELECT
p.name,
p.age,
(select count(*) FROM ORDERS o WHERE o.name = p.name) counter
FROM PEOPLE p
so the 2 columns from different tables both having the same name name can be distinguished.
As suggested by Larnu, try this alternative which does the same by joining the tables and aggregating:
SELECT
p.name,
p.age,
count(o.name) counter
FROM PEOPLE p LEFT JOIN ORDERS o
ON o.name = p.name
GROUP BY p.name
JOIN and aggregation? The subquery will likely result in multiple scans of ORDERS.