How to SELECT 3 table in one query and show all product with price?
Below is my database structure(MySql) :
categories
+-------------+------------+
category_id | parent_id |
+-------------+------------+
1 | 0
2 | 1
3 | 1
4 | 1
5 | 2
6 | 3
products_to_categories
+-------------+------------+
product_id | category_id|
+-------------+------------+
54 | 0
55 | 2
56 | 2
57 | 2
58 | 3
59 | 3
60 | 4
products
+-------------+------------+
product_id | price |
+-------------+------------+
54 | 10.50
55 | 11.20
56 | 1.00
57 | 22.20
58 | 32.0
59 | 32.0
60 | 22.0
Below is my condition ;
1. table categories : parent_id = '1'
(result : 2,3,4)
2. table products_to_categories : category_id = result categories(result : 2,3,4)
(result : 55,56,57,58,59,60)
3. table products : inner join or left join table product to display price where product_id = result products_to_categories(result : 55,56,57,58,59,60)
Final Output
55 - 11.20
56 - 1.00
57 - 22.20
58 - 32.0
59 - 32.0
60 - 22.0
Before i post this question here is my previous query(im stuck how to proceed to condition 2)
$sql_all = mysql_query("SELECT cat.parent_id,cat.category_id FROM categories cat WHERE cat.parent_id='1' ");
while($row = mysql_fetch_array($sql_all)) {
echo $row['categories_id'].'<br/>';
}
thanks.
Try this,
This will display all records from
productstable havingparent_id= 1.