5

i want write a query for the following using where method

SELECT * FROM videos 
WHERE  'privacy' = 'public' OR 
       (privacy = 'private' AND 
       id IN (SELECT vid 
              FROM vid_ads
              WHERE 'aid'=#{current_id}))

I tried using following query but ended with a syntax error

Video.where("privacy = 'public' OR 
            (privacy = 'private' AND id = ?)",
            VidAd.where(:aid => current_id).select("vid"))

Please help

nbbk
  • 1,102
  • 2
  • 14
  • 32

1 Answers1

2

hopefully this shud work!

Video.where("category = #{@static_cat} AND
      privacy = 'public' OR
      (privacy = 'private' AND
      id IN (?))",
      VidAd.where(:aid => current_id).select("vid"))
rohith
  • 106
  • 1
  • 5