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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:05:23+00:00 2026-05-15T21:05:23+00:00

I have a query like this one : SELECT DISTINCT `a`.*, `b`.*, `c`.* FROM

  • 0

I have a query like this one :

SELECT DISTINCT 
      `a`.*,
      `b`.*,
      `c`.*      
FROM `a`     
INNER JOIN `b` ON (`b`.`a_id` = `a`.`id` )     
INNER JOIN `c` ON (`c`.`id` = `b`.`c_id`)       
WHERE (
  (`a`.`id` = 12345) AND
  (`b`.`foo`= "bar")
)

Basically, this takes the row from a with id=12345, and the rows from b that concern this row, as well as the rows from c about this b rows, only of the rows in b have foo=bar

Right now, if there is no b row that has foo=bar, the a row is not even returned. This is wrong. I want that no matter what the matching a row is returned (whether there are bs and cs). How can I do this? (is there a way?)

  • 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-15T21:05:24+00:00Added an answer on May 15, 2026 at 9:05 pm

    I think you should look up how to do OUTER JOINS. It sounds like that might be what you are asking for.

    Something like:

    SELECT DISTINCT 
      `a`.*,
      `b`.*,
      `c`.*
    FROM `a` 
    LEFT OUTER JOIN 
      `b` ON `b`.`a_id` = `a`.`id`
    LEFT OUTER JOIN  
      `c` ON `c`.`id` = `b`.`c_id`
    WHERE 
      `a`.`id` = 12345
    

    EDIT: with new information (a condition on b, which has to have a column foo=bar. This works when there is no row in b at all. but if there is one with foo=notbar, I want it to return a as well), try this. Note: I removed tics to make it easier to read and see quotes.

    SELECT DISTINCT 
      a.*,
      b.*,
      c.*
    FROM a 
    LEFT OUTER JOIN 
      b ON b.a_id = a.id and b.foo = 'bar'
    LEFT OUTER JOIN  
      c ON c.id = b.c_id
    WHERE 
      a.id = 12345
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this query: select top(2) property_id_ref ,image_file ,property_name from property_master a inner join
I have a JPQL like this one: select distinct d from Department d left
Lets say that we have a query like this one: SELECT *, (CUSTOM_EXPRESSION) as
I have query like this : SELECT EXTRACT(MONTH FROM d.mydate) AS synmonth, SUM(apcp) AS
I have a query like this: select empno,name from emp where job = 'CLERK'
I have a query like this: SELECT COUNT(*) AS amount FROM daily_individual_tracking WHERE sales
I like to have a query like this: select data from table where (x
I have a query like this SELECT TOWN, NAME FROM CINEMA WHERE CITY_ID =
I have a query like this SELECT user_id FROM user WHERE user_id NOT IN
I have this query: select distinct pdi.height, pdi.width, pj.jobnum , (select count(barcode) from productiondoorinformation

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.