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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:35:55+00:00 2026-05-30T03:35:55+00:00

I need some help figuring out a query I have 3 tables sources id,

  • 0

I need some help figuring out a query

I have 3 tables

sources
id, name, rank

origin
id, source_id (FK to sources id), name

One source can have many origins

product
id, origin_id (FK to origin id), name, time_added

One origin can have many products

Now, what I want is to select the most recent products per source, ordered by rank descending

Any suggestions?

  • 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-30T03:35:56+00:00Added an answer on May 30, 2026 at 3:35 am

    This should do as you have requested, though without sample output it’s hard to be 100% certain. Inner query selects products linked to the source id ordered by the date added from newest to oldest, and in turn that’s joined to sources and grouped.

    SELECT
      *
    FROM sources AS s
    INNER JOIN (
        SELECT 
            origins.source_id,
            product.*
         FROM origin
         INNER JOIN product
         ON product.origin_id = origin.origin_id
         ORDER BY time_added DESC
    ) AS productsOrdered
    ON productsOrdered.source_id = sources.source_id
    
    ORDER BY s.rank DESC, productsOrdered.time_added DESC
    

    This avoids having to do potentially expensive opreations as the inner select should be pretty fast and can be limited as required

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

Sidebar

Related Questions

Need some help, please. I have a line of horizontal thumbnails loaded as ONE
Need some help from javascript gurus. I have one page where http://www.google.com/finance/converter is embedded
I need some help from the shell-script gurus out there. I have a .txt
I have a 5 byte data element and I need some help in figuring
Hey all, i am in need of some help with figuring out how to
I'm a n00b and I need some help figuring out this issue, I would
I need some help figuring out what I'm doing wrong here. I am trying
I need some help with figuring out Pythons *args and **kwargs . It's simple
I need help figuring out some regular expressions. I'm running the dig command and
I need help in figuring out the solution for my problem. 1. I have

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.