Reputation: 1
I want to list one category from the tables, how can I do this?
Table name: products
product_id desc name price qty
Table name: category
cat_id cat_name
I want it to look like this
Category 1 (shirts)
Name Desc Price Qty
I have this but I get an error.. Not sure if its the right way to do it
SELECT products.*, category.cat_name
FROM prodcuts
LEFT JOIN category ON products.cat_id = prodcuts.cat_id
WHERE category.cat_name = "shirts"
Upvotes: 0
Views: 38
Reputation: 21657
You have an error in your ON statement (you have to have one column from each table to join them) and products is misspelled (prodcuts):
Try this:
SELECT products.*, category.cat_name
FROM products
LEFT JOIN category ON products.cat_id = category.cat_id
WHERE category.cat_name = "shirts"
EDIT:
One other thing is that you say your products table is:
Table name: products
product_id desc name price qty
This has no mention of cat_id. You really have to put that in products table (if this wasn't an error on writing the question)
Upvotes: 1
Reputation: 3682
You have missed category table column name in join.
SELECT products.*, category.cat_name
FROM prodcuts
LEFT JOIN category ON products.cat_id = prodcuts.cat_id
WHERE category.cat_name = "shirts"
should be
SELECT products.*, category.cat_name
FROM products
LEFT JOIN category ON products.cat_id = category.cat_id
WHERE category.cat_name = "shirts"
Upvotes: 0