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 6324737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:45:37+00:00 2026-05-24T16:45:37+00:00

This should be straightforward. I have three tables (relevant columns shown). users : ID,USERNAME,PWD

  • 0

This should be straightforward.
I have three tables (relevant columns shown).

users : ID,USERNAME,PWD

shops: ID,MANAGER_ID (referencing a USER_ID),NETWORK_ID

networks : ID,ADMIN_ID (referencing a USER_ID)

All I need to do, is upon login, check USERNAME and PWD against the ID and to be able to tell if the user that just logged on, is simply in shops table as a manager, or a network admin, or both.

Can this be done with one single SELECT with PHP ?
Thanks !

  • 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-05-24T16:45:38+00:00Added an answer on May 24, 2026 at 4:45 pm
    SELECT
        users.id AS user_id,
        shops.id AS shop_id,
        networks.id AS network_id
    
    FROM users
    
    LEFT OUTER JOIN shops
    ON shops.manager_id = users.id
    
    LEFT OUTER JOIN networks
    ON networks.manager_id = users.id
    
    WHERE users.username = ?
      AND users.pwd = ?
    
    LIMIT 1
    

    When this query returns, shop_id will be non-null if the user is referenced from the shops table, and the same goes for network_id.

    Note that if the user is referenced from the shops or networks table more than once, this query will only produce one row; I assume from your question that you don’t care which shop/network the user is associated with, you only want to check for such an association.

    Alternatively, this query would work too:

    SELECT
        users.id AS user_id,
    
        EXISTS (SELECT shops.id
                FROM shops
                WHERE shops.manager_id = users.id)
            AS has_shop,
    
        EXISTS (SELECT networks.id
                FROM networks
                WHERE networks.admin_id = users.id)
            AS has_network
    
    FROM users
    
    WHERE users.username = ?
      AND users.pwd = ?
    

    One of the queries might be faster than the other depending on what indexes you have set up on the tables, as well as your MySQL version. Consider running them both through EXPLAIN if performance is an issue.

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

Sidebar

Related Questions

This is quite straightforward: I have three tables: Questions: ID (PK) Body QuestionsAndAnswers: QuesionID
This should be pretty straightforward I would think. I have this string: [quote=Joe Johnson|1]Hi![/quote]
I have this fairly straightforward table with ID , Position , Name columns. ID
This should be straight forward for a guru. I don't have any code really
It seems like this should be straightforward but I'm boggling. I've got my listview
I have two tables X and Y . This is back end of a
Seems like this should be something straightforward, but I haven't been able to get
I have a layout that should be fairly straightforward, but for some unknown reason
Shouldn't this be a pretty straightforward operation? However, I see there's neither a size()
This seems like it should be pretty straight forward, but I'm apparently confused. I

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.