Reputation: 1102
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
Upvotes: 5
Views: 1260
Reputation: 106
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"))
Upvotes: 2