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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:49:45+00:00 2026-05-17T19:49:45+00:00

Ok, So I have a table called ‘auctions’ and each auction has a ‘product_id’

  • 0

Ok, So I have a table called ‘auctions’ and each auction has a ‘product_id’ associated.

The auctions table may have 500 items with repeated products.

I want to order by auction_id asc (so newer auctions are shown first), but also only show distinct products. Using distinct doesn’t work, and when I group by the product_id, it doesn’t order the auctions properly.. Here’s what I have

SELECT product_id, auctions.id auctions
INNER JOIN products ON auctions.product_id = products.id
INNER JOIN product_groups ON products.group_id = product_groups.id
INNER JOIN product_images on products.id = product_images.product_id
WHERE products.group_id = '1'
GROUP BY products.id
ORDER BY auctions.id ASC
LIMIT 10

In this example, it does show the unique products, however the order is not correct… if I add auctions.id to the group by, the order is correct, but there are multiple products..

Any help would be awesome – thank you!

  • 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-17T19:49:46+00:00Added an answer on May 17, 2026 at 7:49 pm

    You are not using GROUP BY correctly. You have to use an agregate function on auctions.id if you want the query to be valid, such as MIN to retrieve the smallest auctions.id for every product_id group :

    SELECT product_id, MIN(auctions.id) auctions
    INNER JOIN products ON auctions.product_id = products.id
    INNER JOIN product_groups ON products.group_id = product_groups.id
    INNER JOIN product_images on products.id = product_images.product_id
    WHERE products.group_id = '1'
    GROUP BY products.id
    ORDER BY auctions.id ASC
    LIMIT 10
    

    P.S. You can use alias for your tables in your query which would shorten it.

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

Sidebar

Related Questions

I have table called posts in my DB. Each post has field called social_network
I have a table called ApprovalTasks... Approvals has a status column I also have
I have a table called BlogPost which has a 1-to-many relationship with the Comment
I have table called Direccion other called Cliente each one defined like this public
I have a table called USERS that has a foreign key to the table
Have a table called person. which has personid and contactid. if a person is
I have a table called user_details this table has got morethan 100k user details
I have a table called Shoppings in my SQL db. This one has a
Have a table called user_products that contains a record for each product the user
I have table called product product_id product_Name product_Price product_Description product_image category_id another table category

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.