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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:05:31+00:00 2026-06-13T16:05:31+00:00

I am trying to come up with a query where a 3rd table will

  • 0

I am trying to come up with a query where a 3rd table will join another two. The problem is there are different versions of this first table and I need the query to look at a column in table 1 and then choose the correct table to join but the resulting query must return all rows in table 1 just join an extra table 3 to specific rows which meet the WHERe clause. Is this even possible?

Example:

Table 1 = User

Table 2 = Banners

Table 3 = UserSettings OR AdminSettings OR Nothing

Query would say…

WHERE User.rank='admin' LEFT JOIN AdminSettings

WHERE User.rank='user' LEFT JOIN UserSettings

My current query is this:

$query = "SELECT * FROM Users as U WHERE U.user_id = :id ";
$query .= "LEFT JOIN Banners as B ON U.banner_id = B.banner_id ";
$query .= "LEFT JOIN AdminSettings ON U.server_id = AdminSettings.user_id WHERE U.rank='Admin' ";
$query .= "LIMIT 1";

Problem is that it only shows rows that have User.rank=’admin’ and does not show the rows where User.rank=’user’ rest.

  • 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-13T16:05:32+00:00Added an answer on June 13, 2026 at 4:05 pm

    Try using a IF clause in the fields list, like this:

    $query = "SELECT field1, field2, field3, IF(User.rank = 'admin', A.field, B.field)";
    $query .= " FROM Users as U";
    $query .= " LEFT JOIN Banners as B ON U.banner_id = B.banner_id";
    $query .= " LEFT JOIN AdminSettings as A ON U.server_id = A.user_id";
    $query .= " LIMIT 1";
    

    Something like that should do the trick.

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

Sidebar

Related Questions

I'm trying to come up with a LINQ query that will return the first
I am trying to come up with a query that will return comments following
I'm trying to come up with a way to query the values in two
I'm trying to come up with a way combine two arrays that have different
I am trying to come up with a query that will generate results based
I am trying to write a LINQ query which will return true if there
I'm trying to write a query that follows this logic: Find the first following
I have come up with another question.I am trying to devise a MySql query.
I'm trying to come up with an Access query which is equivalent to this
I am trying to come up with the proper query for my problem. Basically,

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.