I’m trying to write an SQL which gets the number of rows in a table which has the same value as a specific column.
In this case, the table has a column called ‘title’. For each row I return, along with the value of other columns for the row, I want to get the number of rows in the table which have the same value as that row’s ‘title’ value.
For now, the best I have is:
select firstname, lastname, city, state, title, (select count from myTable where title = title);
Obviously, all this gives me is the number of rows in the table in my subselect.
How do I get the right side of the title = to refer to the value of the column’s title?
Thanks for any help, anyone.
this is called “correlated subquery”. It goes like this: