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

1 Answer 1

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"))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.