Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8116595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:53:01+00:00 2026-06-06T03:53:01+00:00

I have the following tables: users +———-+———-+———-+ | id | name | dob |

  • 0

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 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T03:53:03+00:00Added an answer on June 6, 2026 at 3:53 am

    1) This will return the actual count of Authorization of type FB for every user :

    `

    Select Name UserName, ID UserID, COUNT(FBAuth) FBAuthCount
    from Users LEFT JOIN
    (Select UserID, COUNT(AuthType) FBAuth from Auth 
    Where AuthType = 'FB'
    Group by USERID) Auths on (Users.ID = Auths.UserId)
    Group by ID, Name
    

    `

    2) This will return the flag true or false for every user depending on thier authorization type:

    `

    Select Name UserName, ID UserID, 
    CASE WHEN COUNT(FBAuth) > 0 THEN 'TRUE' ELSE 'FALSE' END FBAuthFLAG
    from Users LEFT JOIN 
    (Select UserID, COUNT(AuthType) FBAuth from Auth 
    Where AuthType = 'FB'
    Group by USERID) Auths on (Users.ID = Auths.UserId)
    Group by ID, Name
    

    `

    Using a join on smaller dataset: faster response.
    Finally, I believe this is the one:

    `

    SELECT users.id,
           users.email,
           users.name,
           users.sid,
           users.created_at,
           ( CASE
               WHEN fb_auth > 0
               THEN 'true'
               ELSE 'false'
             END ) AS facebook
    FROM   users
           LEFT JOIN (SELECT authentications.user_id,
                             Count(authentications.provider) fb_auth
                      FROM   authentications
                      WHERE  provider = 'facebook'
                      GROUP  BY user_id) auths
                  ON ( users.id = auths.user_id )
    GROUP  BY users.id,
              users.email,
              users.name,
              users.sid,
              users.created_at
    

    `

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following tables/views Users (View) -> UserId -> Name Roles (Table) ->
I have following tables questions -> id, question_data, user_id users -> id, fname, lname
I have 3 tables with the following columns : * users : user_id *
I have the following table for storing user data: e.g. TABLE: users COLUMNS: ...
I have the following tables: People Users Emails The user's password is stored in
I have the following tables: create table Users( Id uniqueidentifier primary key, InfoId uniqueidentifier
I have the following tables: USERS table id username email password status FRIENDS table
I Have the following tables Users -> UserId -> Name Roles -> RoleId ->
I have the following tables: users: user_id user_name message: message_id thread_id to_id from_id title
I have the following tables: users userId|name items itemId|userId|description What I want to achieve:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.