My question is very simple but I can't find any solution to this. Please help me someone as I'm stuck very bad.
My table is this.
users_table:
id | name | admin | property_id
-----------------------------------
1 | x | 1 | 0
2 | y | 1 | 0
3 | z | 0 | 1
4 | t | 0 | 2
4 | u | 0 | 2
4 | o | 0 | 2
I have two records
which are admin
and some other records
which belong to one of these two records by matching the property_id
with the id
.
In the end what I want is the admin
row data and the count
of its properties
.
The problem is that the data is all in the same table.
This is what should be the output from the desired query.
id | name | admin | property_count
-----------------------------------
1 | x | 1 | 1
2 | y | 1 | 3
I hope I could explain myself clear enough. Thanks in advance.