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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:49:52+00:00 2026-05-27T14:49:52+00:00

So I have 2 tables … Products and Images Products ——— id value1 value2

  • 0

So I have 2 tables … Products and Images

Products 
---------
id
value1
value2
value3
etc..

Images
---------
id
productId
imageName

The image table will have more than one image per product, so when I run this query:
(the != 0 is because some images don’t have a productId so I want to exclude them, not sure if there is a better way to handle that, or if I even need to include that)

select p.*, i.imageName 
from products p, images i 
where p.id = i.productId and i.productId != 0 

I get the results, but it gives me multiple entries and I just want one result per product and i want it to pull up THE IMAGE THAT WAS ADDED FIRST (so the oldest one) …

Currently the results look like this —

id : 1
imagename: name1.jpg

id : 2
imagename: name5.jpg

id: 2
imagename: name6.jpg

id: 2
imagename: name7.jpg

id: 3
imagename:  name3.jpg

etc... etc... 

I want it to look like this …

id: 1
imagename: name1.jpg

id: 2
imagename: name5.jpg

id: 3
imagename: name 3.jpg

Does this makes sense? Can anyone help me figure out my problem?

  • 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-27T14:49:53+00:00Added an answer on May 27, 2026 at 2:49 pm

    Something like this would work, although you will have to check it for typos.

    SELECT p.*,
           (SELECT i.imageName
              FROM images
             WHERE i.productId = p.id
            ORDER BY i.date_created ASC
             LIMIT 1)
              AS imageName
      FROM products p
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tables Products, Sales and ProductsInStores. ProductsInStores table keeps track of how many
I have tables linked by FK, I query on the first table using entity
Hi i have tables like this : table entry : id | total_comments _____________________
I have tables: Teachers and Students. We have a SpecialProjects Table where Teachers and
I have tables item and store (it's a store management system). item table has
I have tables foo and bar: create table foo(a int, b varchar(10), primary key
I have tables & data like this: venues table contains : id +----+---------+ |
I have tables of data samples, with a timestamp and some data. Each table
I have tables named Events and Log. The Events table comprises of ID, Event
I have tables like Customer , Purchase etc which sometimes have associated documents with

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.