I have the following tables:
users
+----------+----------+----------+
| id | name | dob |
+----------+----------+----------+
authentications
+----------+----------+----------+
| id | user_id | provider |
+----------+----------+----------+
A user, has-many authentications. user_id in the authentications table is a foreign key to the users table.
Im trying to comple the following output:
+---------------+---------------+---------------+---------------+
| user.id | user.name | user.dob | C |
+---------------+---------------+---------------+---------------+
Here, C is, the count of the users authentications where provider is ‘facebook’. If instead of the count, I could get a boolean value, ie true if authentications are present, false if not, that would be even better.
I cant figure how to go about constructing the query. Any pointers would be much appreciated.
1) This will return the actual count of Authorization of type FB for every user :
`
`
2) This will return the flag true or false for every user depending on thier authorization type:
`
`
Using a join on smaller dataset: faster response.
Finally, I believe this is the one:
`
`