user3521051
user3521051

Reputation: 83

Display the details from one table and count from another table

need to fetch id, name, address details of a man from one table and and number of properties from another table belonging to him

we tried this way

select person.* count(property.id) from person, property where person.id = property.id

Upvotes: 0

Views: 38

Answers (1)

juergen d
juergen d

Reputation: 204766

This is how you should do it

select person.id, person.name, person.address,
       count(property.id) 
from person
left join property on person.id = property.id
group by id, name, address

Group by all fields that are not aggregated (counted). And then use the explicit join syntax. The other is just outdated since decades.

Upvotes: 1

Related Questions