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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:48:31+00:00 2026-06-16T09:48:31+00:00

I have two tables listings and bids. I have a query that will return

  • 0

I have two tables “listings” and “bids”. I have a query that will return all the listings that a particular user has bid on, where the end_date is past. What I need to do though is limit the results even further to find only the listings where the user has bid, and is the last bidder. Here is the query I have so far…

SELECT listings.end_date, listings.user_id, listings.title, listings.auc_fp, listings.id, listings.auc_image1 
FROM listings INNER JOIN bids ON listings.id = bids.listing_id 
WHERE bids.user_id=$userid 
AND listings.end_date < NOW() 
ORDER BY list_ts DESC"

I’m not good with subqueries and I’m assuming I’m going to need one here to find all the users bids in the “bids” table where the bid_ts (bid timestamp) is the lastest timestamp for that corresponding listing_id in the bids table. The columns in my bids table are: listing_id, user_id, bid, bid_ts.

+------------+---------+------+---------------------+
| listing_id | user_id | bids | bid_ts              |
+------------+---------+------+---------------------+
|  1         | 10      | 100  | 2012-11-16 00:54:03 |
|  1         | 11      | 101  | 2012-11-16 00:54:04 |
|  2         | 10      | 33   | 2012-11-16 00:54:03 | 
|  2         | 11      | 34   | 2012-11-16 00:54:04 |
|  2         | 12      | 35   | 2012-11-16 00:54:05 |
+------------+---------+------+---------------------+

Thanks for any help

  • 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-06-16T09:48:32+00:00Added an answer on June 16, 2026 at 9:48 am
    SELECT  a.*
    FROM    tableName a
            INNER JOIN
            (
                SELECT listing_ID, user_ID, MAX(bid_ts) maxDate
                FROM tableName
                GROUP BY listing_ID, user_ID
            ) b ON  a.listing_ID = b.listing_ID AND
                    a.user_ID = b.user_ID AND
                    a.bid_ts = b.maxDate
    
    • SQLFiddle Demo
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have two tables, user and comment . They have table definitions that
I have two tables user table user_id | name | 1 | peter |
I have two tables, a user table and a application table: User id username
I have two tables in my MySQL database, one is a library of all
I have tables with listings, categories and one that maps them to each other.
I have two tables, that relate via a one-to-many relationship i.e tableOne (1)----------(*) tableTwo
I have two tables: groups and group_members . The groups table contains all the
I have two tables: listings(item_id, ...) images(item_id, ...) The item_id value is the same
I have two tables: events_archive and reports. The events table shows all information about
Let's say I have these two tables: Product and Storage Product has a ProductId,

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.