SQL QUERY:
SELECT
c.id AS c_id,c.image AS category_image,b.id AS p_id,b.image AS product_image,
a.id as product_id,0 AS sc_id,0 AS sub_category,0 AS is_active2, a.*,b.*,c.*
FROM stock_50644 a
JOIN product b ON a.product_id = b.id
JOIN category c ON b.category = c.id
WHERE b.category=1 ORDER BY p_id ASC
If stock_50644
has no product
entry then i am getting empty result. How can i make it return all product with stock value null if stock is empty
EDIT:
PRODUCT ; STOCK_50644
id product_name category_id ; id product_id price
---- -------- ---------- --------------- ; ---- --------- ----- --------------
1 name1 1 ; 1 2 15
2 name2 2 ;
if i put WHERE b.id=1
in below query im getting correct expected output.
But as soon as i replace it by ORDER BY b.id ASC LIMIT 1;
it is taking forever time and then #2013 - Lost connection to MySQL server during query
SELECT
c.id AS c_id, c.image AS category_image, b.id AS p_id, b.image AS product_image,
a.id AS product_id, 0 AS sc_id, 0 AS sub_category, 0 AS is_active2, a.*,b.*,c.*
FROM stock_50644 a
RIGHT JOIN product b ON a.product_id = b.id AND b.category = 1
LEFT JOIN category c ON b.category = c.id
WHERE b.id=1
ORDER BY b.id ASC LIMIT 1;