skip to Main Content

Having the following MySQL tables:

products: id, name, description
categories: id, name, description
prodcat: id_product, id_catategory 

How can I select all the "products" fields and all the
"categories" fields of the products that have not been associated to a category?

How can I associate products to a category ? (PHPMyAdmin – SQL)

Product:
ID Name Description
1- Nike_Pegasus_Zoom – running_shoes
2- Adidas Jacket – jacket
3 – Adidas Telstar – ball

Categories:
ID Name Description
1 Shoes
2 Clothes

Must to associate the products to a category!

2

Answers


  1. i didn’t understand well your question but I guess you want to have all products that don’t have a category associated

    select * from products where id not in (select id_product from prodcat)
    
    Login or Signup to reply.
  2. Maybe just a join would be enough…

    SELECT p.* 
    FROM products p 
    JOIN prodcat pc ON p.id = pc.id_product
    WHERE pc.id_category IS NULL
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search