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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:18:57+00:00 2026-05-23T08:18:57+00:00

My tables product pid name 1 AA 2 bb 3 cc History table hid

  • 0

My tables

product

pid name

1    AA
2    bb
3    cc

History table

hid pid uid 
1    1   1
2    1   2
3    1   1  // this one should join with pid 1
4    3   2  // this one should join with pid 3
5    2   3
6    2   1 // this one should join with pid 2

I like to display most recent bidder on a product.The history tables stores bidder
details.if no bid on product just need to return null.

Thanks

  • 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-23T08:18:58+00:00Added an answer on May 23, 2026 at 8:18 am

    How about something like

    SELECT  *
    FROM    product p LEFT JOIN
            (
                SELECT  ht.*
                FROM    History_table ht INNER JOIN
                        (
                            SELECT  pid,
                                    MAX(hid) last_hid
                            FROM    History_table ht
                            GROUP BY    pid
                        ) lstItem   ON  ht.pid = lstItem.pid
                                    AND ht.hid = lstItem.last_hid
            ) ht    ON  p.pid = ht.pid
    

    First you need to retrieve the MAX hid per pid, which by definition should be the most recent entry.

    Then join that back to the same history table to retrieve the uid.

    And lastly join this (LEFT JOIN) back to the actual products table.

    Hope that helps.

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

Sidebar

Related Questions

I have two tables like this Table Product ProductId - int <PK> ProductExpiry -
I have 2 tables, defined as such: CREATE TABLE `product` ( `pid` SMALLINT( 5
I have two mySQL tables as follows: [product] table P_id | Name | Quantity
I have two tables that look like this: Products: id category name description active
I have 2 tables -- one has ProductID , [Product Name in English] and
I have a product table: Product - PId - Name ProductPricing - PPId -
I have 3 tables with values like below **tbl_product** recID pID price colour 1
how to make a good MySQL Database Table Structure from this XML-Code? <xml> <product>
I have two tables: Product ------------------------------------ id group_id name quick_select ------------------------------------ 1 1 product1
I have the following five tables: ISP Product Connection AddOn AddOn/Product (pivot table for

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.