2017-02-27 1 views
-2
で句で使用

クエリ1の場合:つだけの行が示されている、SQL

select products 
from buyde_deal 
where displayflag = '1' 
and end_date> now() 
and start_date < now() limit 1 

出力:query 1 output

照会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` " 

出力:query 2 output

場合2番目のクエリを実行すると、1つのレコードのみが返されます。私は表1のすべての記録が必要です。

+1

の可能性のある重複した[IN(とvarchar型の列で選択)状態とのint値の一部は、すべての行を返す](http://stackoverflow.com/questions/2064766/ select-by-varchar-column-in-part-in-condition-and-value-returns-all-r) –

答えて

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` 
+0

@SaurabhRanjan FIND_IN_SETは、1NF以外のデータベーステーブルに対する救済者です。 https://en.wikipedia.org/wiki/First_normal_formテーブルを変更する権限がある場合は、csvカラムを別のテーブルに移動してください – mickmackusa

+0

まずはありがとうございました。あなたは私にこの問題を解決するもう一つの方法を教えてくれました。
あなたは「FIND_IN_SETが非1NFデータベーステーブルへの救い主である」とはどういう意味ですか? – inrsaurabh

関連する問題