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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:23:07+00:00 2026-06-10T16:23:07+00:00

I am trying to write a query that will pull some product information AND

  • 0

I am trying to write a query that will pull some product information AND photos, if the product has any.

select
    prod.pID, prod.Manufacturer_Name, prod.pUPC, prod.pNum, prod.pPrice, prod.pSalesPrice, prod.pSalesDate, prod.pSalesEndDate, prod.pSale,
    GROUP_CONCAT(photoName) as photos
from
    ds_products as prod
    inner join ds_photos as pics on pics.objectID=prod.pID
where
   pics.photoFlag =2
group by 
   prod.pID

The problem with this is that products that do not have photos get left out of the result set. What do I need to add and/or change to allow for a product that doesn’t appear in the photos table to show up in the results?

Thanks

EDIT

I tried the LEFT JOIN instead of inner but get the same result set. If i run just:

select
    prod.pID, prod.Manufacturer_Name, prod.pUPC, prod.pNum, prod.pPrice, prod.pSalesPrice, prod.pSalesDate, prod.pSalesEndDate, prod.pSale
from
    ds_products as prod

I get about 600k results. The inner and or left join queries get about 190k results. Is there another way to do this?

  • 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-10T16:23:08+00:00Added an answer on June 10, 2026 at 4:23 pm

    Use outer join

    select
        prod.pID, prod.Manufacturer_Name, prod.pUPC, prod.pNum, prod.pPrice, prod.pSalesPrice, prod.pSalesDate, prod.pSalesEndDate, prod.pSale,
        GROUP_CONCAT(photoName) as photos
    from
        ds_products as prod
        LEFT join ds_photos as pics on pics.objectID=prod.pID
    where
       pics.photoFlag =2 OR pics.photoFlag is NULL
    group by 
       prod.pID
    

    I have added a condition which check if photoFlag is null for the products which don’t have corresponding pics
    Here is working fiddle : http://sqlfiddle.com/#!2/c2a9c/1/0

    For more information: http://dev.mysql.com/doc/refman/5.0/en/outer-join-simplification.html

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

Sidebar

Related Questions

My users submit information for locations. I'm trying to write a query that will
Im trying to write a query that will pull the value of the selected
I am trying to write a query that will select rows based on the
I'm trying to write a query that will pull back the two most recent
I am trying write a query that will display if the person has anyone
I'm trying to write a query in php that will select a row from
Beginner here! I am trying to write a query that will select the 3
I'm trying to write a query that will return the closest match from a
I am trying to write a linq query that will only return certain columns
I'm trying to write a custom SQL query that will create a list of

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.