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

  • Home
  • SEARCH
  • 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 3754754
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T09:35:37+00:00 2026-05-19T09:35:37+00:00

**Table parent** parentId | name **Table children** childId | parentId | pictureId | age

  • 0
**Table parent**
parentId | name

**Table children**
childId | parentId | pictureId | age

**Table childrenPictures**
pictureId | imgUrl

no i would like to return all parent names with their eldest son’s picture (only return parents that have children, and only consider children that have pictures)

so i thought of something like :

SELECT c.childId AS childId,
   p.name AS parentName,
   cp.imgUrl AS imgUrl,
   MAX(c.age) AS age
FROM parent AS p
   RIGHT JOIN children AS c ON (p.parentId = c.parentId)
   RIGHT JOIN childrenPictures AS cp ON (c.pictureId = cp.pictureId))
GROUP BY p.name

This query will return each parent’s eldest son’s age, but the childId will not correspond to the eldest sons id, so the output does not show the right sons picture.

  • 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-19T09:35:37+00:00Added an answer on May 19, 2026 at 9:35 am

    you need to pre-query per family to get the age of the oldest child that has an image, then get parent’s name / image information… something like…

    select
          PreQuery.parentID,
          p.Name ParentsName,
          c.childID,
          c.age,
          cp.imgUrl
       from 
          ( select 
                  c.parentID,
                  max(c.age) OldestChildAgeWithPicture
               from
                  Children c,
                  childrenPictures cp
               where
                  c.pictureID = cp.pictureID
               group by 
                  c.parentID ) PreQuery,
          Parent p,
          Children c,
          ChildrenPictures cp
       where
              PreQuery.parentID = p.parentID
          and PreQuery.parentID = c.parentID
          and PreQuery.OldestChildAgeWithPicture = c.age
          and c.pictureID = cp.pictureID
    

    The inner query is prequalifying just by parent, childs highest age that an image exists… So, if you have a family with 3 children, oldest has no picture, 2nd oldes DOES, the the 2nd oldest is the one that will show in the above query. Additionally, what do you want to do if a family has twins, and BOTH have pictures on file. This query would show BOTH children if age is based on actual integer representation. However, if age is computed based on date arithmetic and would be more accurate… Ex: one child born Jan 1 of year X, and within the same year, another child born Dec 1…. As of December, they would be the same integer based age, but one obviously 11 months older than the other.

    Additionally, if you want the oldest REGARDLESS of having a picture, the above query would have to be changed only slightly… let me know if this is what you are looking for.

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

Sidebar

Related Questions

I have a table like this: Item { int ItemID int ParentID string Name
I have db table with parent child relationship as: NodeId NodeName ParentId ------------------------------ 1
How can I set parent-child relation on same table? Id int, title string, ParentId
I need to be able to return a list of all children given a
Here is an example of what I've got going on: CREATE TABLE Parent (id
My table has data like so products_parent_id | products_quantity 2 5 2 7 2
I have a table which defines a child-parent relationship between nodes: CREATE TABLE node
I have the following table relationship in my database: Parent / \ Child1 Child2
How can i make the inner table to overlap the parent div with 5
I have table witch contains fields: id, parent_id, name (etc.) i want to order

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.