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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:02:41+00:00 2026-05-23T12:02:41+00:00

I am trying to unify a pair of queries with a LEFT JOIN ,

  • 0

I am trying to unify a pair of queries with a LEFT JOIN, so that I can perform an ORDER BY on a desired column.

Table A has an exclusive one-to-many relationship with Table B, and table B has an exclusive one-to-many relationship with Table C.

I want to get the maximum value of a column in Table C, for each row in Table A.

what I used to have was:

$tableA = SELECT * FROM tableA;
for each row in $tableA {
  $maxValue = SELECT MAX(value) FROM tableC WHERE tableB_id IN (SELECT tableB_id FROM tableB WHERE tableA_id={$row['tableA_id']}) GROUP BY tableB_id;
}

and now I’m thinking along the lines of:

SELECT * FROM tableA LEFT JOIN (SELECT tableA_id, MAX(max_c_value) FROM (SELECT tableB_id, MAX(value) max_c_value FROM tableC GROUP BY tableB_id) t GROUP BY tableA_id) USING(tableA_id)

but I know that’s gibberish. I am not sure where to go from here.
I’m finding it hard to explain the problem, sorry.

  • 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-23T12:02:41+00:00Added an answer on May 23, 2026 at 12:02 pm
    SELECT A.ID, MAX(C.MyField) as CField
    FROM A
        LEFT OUTER JOIN B
            ON A.ID = B.A_ID
                LEFT OUTER JOIN C
                    ON B.ID = C.B_ID
    GROUP BY A.ID
    

    You will get null value for CField if there is no rows corresponding.

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

Sidebar

Related Questions

I am trying to implement a unify function with an algorithm that is specified
I'm trying to implement this scenario using Unity and i can't figure out how
Trying to make this jQuery filter that uses .find case-insensitive. For example, when the
Trying to figure out how I can do this properly. The print_r looks like
I'm trying to find any documentation on Unity configuration but it now seems that
I'm trying out Unity and I'm having problems declaring my viewmodel in XAML. Can
I'm trying to invoke the RegisterType method in the Unity container. RegisterType has a
We're trying to use Dependency Injection for a WCF Service. The Service has a
I was trying to unify the lines in my file when I observed the
I have a basic class that is trying to resolve an interface using Unity.

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.