How doing a sql select with where mandatories joining 'or wheres'?

3277 views sql
1

I need making this select:

select * from posts where active = 1 //mandatory where url <> 'thisurl' //mandatory or where id1 = 1 or where id2 = 2

Is it clear to understand? In adition i´m using Codeigniter active record, so if someone could help me in translating that, i´ll be thankfull.

answered question

2 Answers

11

you can do this

SELECT* 
FROM posts 
WHERE active = 1       //
AND url <> 'thisurl' //mandatory
OR id1 = 1 
OR id2 = 2

posted this
13

Try like below

 select * from posts where active = 1       //mandatory
                     and url <> 'thisurl' //mandatory
                     and ( id1 =1 or id2 =2)

posted this

Have an answer?

JD

Please login first before posting an answer.