Best way to get Count as field in Sql select statement
I have 2 tables: Person and Orders
Person
Id Name Age
1 name1 1
2 name2 2
Order
Id Amount PersonId
1 30 1
2 40 2
3 30 2
4 40 2
5 30 1
6 40 2
7 30 1
8 40 2
And i want users details with total number of orders , So for this purpose I have 2 solutions:
1. select p.Name,p.Age,(select count(1) form orders o where o.personId= p.Id as cntVal
from Person p
2. select p.Name,p.Age,cntVal
from Person p
inner join (select personId,count(1) as cntVal from orders o group by PersonId) cnt
on cnt.personId=p.Id
We have around 200K records in Person and 15K in Order table. I wanted to know which one is better approach ? Or you can suggest me a faster query