查询1:
select products
from buyde_deal
where displayflag = '1'
and end_date> now()
and start_date < now() limit 1
输出:
查询2:
SELECT id,productname ,cat_id ,subcat_id,shortdescription1,shortdescription2,shortdescription3 ,sellingprice,sellpricevat,mrp,regularprice,costprice,sku,qty,pweight,seller_id,shippingcost,color,size,discount
FROM `buyde_product`
WHERE id IN (
select products
from buyde_deal
where displayflag = '1'
and end_date> now()
and start_date < now() )
ORDER BY `buyde_product`.`id` "
输出:
如果我运行第二个查询,则只返回一条记录。我需要表1中的所有记录。
答案 0 :(得分:0)
尝试使用find_in_set
:
SELECT id,
productname,
cat_id,
subcat_id,
shortdescription1,
shortdescription2,
shortdescription3,
sellingprice,
sellpricevat,
mrp,
regularprice,
costprice,
sku,
qty,
pweight,
seller_id,
shippingcost,
color,
size,
discount
FROM `buyde_product`
JOIN (SELECT products
FROM buyde_deal
WHERE displayflag = '1'
AND end_date > Now()
AND start_date < Now()) t
ON FIND_IN_SET(`buyde_product`.`id`, t.products)
ORDER BY `buyde_product`.`id`