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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:40:53+00:00 2026-05-11T20:40:53+00:00

I have 2 tables, a product table and an image table. Products can have

  • 0

I have 2 tables, a product table and an image table. Products can have more than 1 image per record. I need an SQL statement that will list 1 image per product rather than all images per product.

A scaled down example of my current effort is:

SELECT Product.RefCode, Img.ImgPath
FROM Product INNER JOIN (
    SELECT ProductImg.ImgPath, ProductImg.PrdFK
    FROM ProductImg 
    LIMIT 0,1) AS Img ON Product.PrdID = Img.PrdFK;

The above example returns 0 results, however, if I remove the LIMIT 0,1 from the Sub SELECT I get a complete list of all products and all images.

I just want 1 image record per product record to be returned.


I have revised “a programmer” code to MySQL and it works fine.

SELECT Product.RefCode, 
        (Select ProductImg.ImgPath
         From ProductImg
         Where Product.PrdID = Img.PrdFK LIMIT 0,1) AS ImgPath
FROM Products

For some reason when trying “Bill Karwin’s” solution, it sent the server loading for a long time.

  • 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-11T20:40:53+00:00Added an answer on May 11, 2026 at 8:40 pm

    This should work:

    SELECT Product.RefCode,
           (Select Img.ImgPath
            From ProductImg
            Where Product.PrdID = Img.PrdFK LIMIT 0,1) As ImgPath
    FROM Product
    

    If you have a way to determine which image should the select return, then you can add a where and maybe an Order By in the sub-select.

    In the following example, we’ll get only the latest of the active images.

    SELECT Product.RefCode,
           (Select Img.ImgPath
            From ProductImg
            Where Product.PrdID = Img.PrdFK
              And IsActive = 1
            Order By EntryDate Desc LIMIT 0,1) As ImgPath
    FROM Product
    

    Edited and corrected ‘Top 1’ to ‘Limit 0,1’.

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

Sidebar

Related Questions

I have a table of products in my sql database. Each product has an
Now I have 4 tables: table categories: -id -category table products: -id -product -price
I have a products table containing products. Each product can have multiple images. The
I have 2 tables product and history product table: id name type price location
My prob in brief: I have two tables namely category and product. table: category
I have a question. I have here 2 tables table 1 : products product_id
I have a cart table which has a relation to a product table that
I have 2 tables, one called products and one images. The table images hold
I have some sql that gathers product information. It also retrieves images from joined
I currently have a table listing all of the products that are in the

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.