SELECT Table1.Col1, Table1.Col2, Table1.Col3, **Table2.Col1**
FROM Table1
JOIN Table2 ON Table1.ID = Table2.ID
WHERE condition1
AND condition2;
This returns the list as expected.
Here's where I'm stuck: Table2.Col1 has 8-15 records for each Table1.ID. I want to display the count for each Table2.ID aligned with the row for Table1.ID.
I can get the total count of a Table2.Col1 condition but I don't know how to align it to the relevant row- Table1.ID.
CodePudding user response:
SELECT Table1.Col1, Table1.Col2, Table1.Col3, COUNT(Table2.Col1)
FROM Table1
JOIN Table2 ON Table1.ID = Table2.ID
WHERE condition1
AND condition2
GROUP BY Table1.Col1, Table1.Col2, Table1.Col3