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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:27:38+00:00 2026-06-02T08:27:38+00:00

I have two tables in a database. One is for products and the other

  • 0

I have two tables in a database. One is for products and the other is for product images. I’m joining the tables so that I can get the product images and info with one query:

SELECT * 
from items left join images 
     on items.item_id = images.item_id and 
        items.display_items = '1' and items.active = '1' 
order by items.item_year desc, items.fullname desc, images.position asc

I noticed, however, that all of the products weren’t showing up. Some of the products don’t have any images and those were the ones not appearing. I ran my query in Sequel Pro and saw that the column item_id was appearing twice, once with the id and once as NULL. How can I fix my query to get all of the products?

  • 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-02T08:27:45+00:00Added an answer on June 2, 2026 at 8:27 am

    I would revise your query to specify the exact columns you want in your result rather than use “select *”. In this case, you may have columns with the same name in the 2 tables (such as “item_id”), and this can cause problems in “select *”.

    Also, I would take the 2nd line of your ON statement and put it in a WHERE clause. The “items.display_items = ‘1’ and items.active = ‘1’” doesn’t apply to your join, but rather to the set of items you want.

    Revised query:

    SELECT --explicit list of columns 
    from items 
        left join images 
        on items.item_id = images.item_id  
    WHERE items.display_items = '1' and items.active = '1' 
    order by items.item_year desc, items.fullname desc, images.position asc
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two related tables in my database: Page and Tag. One Page can
I have two tables in a derby database that I want to query together.
In a MySQL database I have two tables linked in a join. One table
I have two tables in my database schema that represent an entity having a
I have two tables in my database that look like that: Customer: C_ID city
I have two tables in my database table1, table2. I have a join query
I have two tables. One contains a list of products with the primary key
I have two tables in a one to many relationship. (products and qty break
I have two tables. One in one database and one in a separate database.
I have a database table which stores products. Each product can have multiple colours.

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.