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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T09:16:34+00:00 2026-05-19T09:16:34+00:00

After spending a few months pondering how i was going to JOIN tables together

  • 0

After spending a few months pondering how i was going to “JOIN” tables together which share same named columns and outputting them in a format which can be searched and paged i came up with this solution, whereby it creates a “column” with a set name, such as stock_levels and enters the values as JSON so it can be parsed out afterwards.

This works exactly as intended, however the problem i have come accross is the “WHERE” section, ( product.id = quantity.product_id ) returns all of the elements in quantity which the id of product, however if there arnt any elements in quantity with that product id, the product itself is not returned, as new products entered into the system neither have any stock or images, they are not return by the system.

My question is thus, is there a way of basically doing this ( but ofc with code that works )

WHERE ( `product`.`id` = `quantity`.`product_id` OR COUNT( `product`.`id` = `quantity`.`product_id` ) = 0 )

( ie return the product if it has no entries in quantity )

And here is the code of the query used:

SELECT DISTINCT `product`.*, 
CONCAT( '[', GROUP_CONCAT( '{', '"id":"', `quantity`.`id`, '"', ',', '"sku":"', `quantity`.`sku`, '"', ',', '"product_id":"', `quantity`.`product_id`, '"', ',', '"criteria":"', `quantity`.`criteria`, '"', ',', '"quantity":"', `quantity`.`quantity`, '"', ',', '"price":"', `quantity`.`price`, '"', '}' SEPARATOR ',' ), ']' ) as `stock_levels`, 
CONCAT( '[', GROUP_CONCAT( '{', '"id":"', `product_image`.`id`, '"', ',', '"product_id":"', `product_image`.`product_id`, '"', ',', '"location":"', `product_image`.`location`, '"', ',', '"type":"', `product_image`.`type`, '"', ',', '"order":"', `product_image`.`order`, '"', '}' SEPARATOR ',' ), ']' ) as `images`
FROM (`product`, `quantity`, `product_image`)
WHERE ( `product`.`id` = `quantity`.`product_id` ) 
AND ( `product`.`id` = `product_image`.`product_id` ) 
AND `online` = 1
GROUP BY `product`.`id`
ORDER BY date_added desc
  • 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-19T09:16:34+00:00Added an answer on May 19, 2026 at 9:16 am

    You want to convert your inner joins to Left Joins

    FROM
     product p
     LEFT JOIN quantity q
     ON p.id = q.product_id
     LEFT JOIN product_image pi
     ON p.id = pi.product_id 
    WHERE
     p.online = 1
    

    This assumes that online is in the product table if its not you’ll need to move it into the JOIN.

    Also you should be using ANSI 92 joins anyway

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

Sidebar

Related Questions

After spending the last few months learning about MATLAB, it seems I need to
We initially didn't use any logging or debug tracing but after spending few weeks
EDIT: After spending several hours researching this, I don't think I'm going to find
After spending few hours on the internet to find about push notification system for
After spending a few days of trying to find an answer online, I figured
I am sure I am doing something wrong, but after spending a few hours
I'm new to java and android development. After spending few days working with java
After spending a few weeks on an App for my company all my questions
After spending roughly two days on this, I'm getting a little rattled. Although by
After spending three weeks learning Objective-C and Cocoa programming for my work, I've been

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.