I have 3 tables temp_cart, product,plan
temp_cart - prod_id
product - prod_id, plan_id
plan - plan_id, title
I have temp_cart.prod_id = 40
Please suggest me mysql_query.
SQL query is shown below. Basically you need to join the tables.
select plan.plan_id, plan.title from temp_cart t
inner join product p on t.prod_id = p.prod_id
inner join plan on plan.plan_id = p.plan_id
where t.prod_id = 40
SELECT temp_cart.prod_id, plan.prod_id, product.prod_id FROM product INNER JOIN temp_cart ON temp_cart.prod_id=product.prod_id;
This may help you:-
select product.prod_id, plan.plan_id, plan.title from product
inner join plan on product.plan_id=plan.plan_id
inner join temp_cart on temp_cart.prod_id=product.prod_id
where temp_cart.prod_id=40
If you only want plan from your temp_cart you could do like this:
select *
from plan
where plan_id in (
select plan_id from plan where prod_id in (select prod_id from temp_cart)
)
Try this: It will help you
SELECT p.plan_id,p.title FROM plan as p INNER JOIN product as pr ON
pr.plan_id=p.plan_id INNER JOIN temp_cart as tc ON
tc.prod_id=pr.prod_id WHERE tc.prod_id=40.