i have 2 tables called products and categories, i have categories_id is a foreign key in the table products, but when i did that query it calls NULL.
i want to use the value of the foreign key to make sub query to select the category name from the table categories and return the name of the category with the products query, here is the code .
select products_name, products_image,
products_art_number, products_color, (select categories_name
from categories where categories_id='categories_id'), sub_categories_id
from products where products_id = '$this->id'
SELECT p.products_name
, p.products_image
, p.products_art_number
, p.products_color
, c.categories_name
, s.sub_categories
FROM products p
INNER
JOIN categories c
ON c.categories_id = p.categories_id
INNER
JOIN sub_categories s
ON s.sub_categories_id = p.sub_categories_id
WHERE p.products_id = '$this->id'
SELECT
p.products_name,
p.products_image,
p.products_art_number,
p.products_color,
c.categories_name
FROM
products p
LEFT JOIN
categories c
ON
c.categories_id = p.categories_id
WHERE
p.products_id = '$this->id'