I'm trying to figure out how to write a script to select certain records/fields from one table, then join it to another table and include a column for a corresponding count. For example, this is what I have now:
select ID, Val from OriginalTable where Something = 1
Now I have another table which has records linking to this original table, where the a column OriginalID
matches the ID
of the OriginalTable
. One example would be:
select * from OtherTable where OriginalID = 3
...where 3 = the ID
of the OriginalTable
.
What I'd like to do is add a column to the first statement which shows a count of the other table as shown in the second query. For example, this might be a result set:
ID Val Count
1 abc 15
2 def 23
3 ghi 42
4 jkl 19
How do I write this query to include this count?