简体   繁体   中英

How to write nested query in ruby on rails?

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

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"))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM