user2781627
user2781627

Reputation: 455

Combined And and Or query in sqlite

Select * 
FROM dummytable 
WHERE 
    ( minagegrp >=7 AND minagegrp <= 9)
 OR ( maxagegrp >= 7 AND maxagegrp <= 9 )
 OR (minagegrp <= 7 AND maxagegrp >= 9 )  
ORDER BY apptitle DESC

I am actually not able to understand why is this query not returning me result properly.

Condition is -: Return those rows which have either of the given conditions true.

Please help !!

Upvotes: 0

Views: 405

Answers (1)

ngrashia
ngrashia

Reputation: 9904

So many conditions not required. Below itself would solve your issue:

Condition 1 says: Min value = 7,8,9

Condition 2 says : Max value = 7,8,9

Condition 3 says: Min <7 or Max > 9

  • From 1 and 3, Min can be anything till 9.
  • From 2 and 3, Max can be anything above 7.

So, The below query would help you achieve your result.

Select * FROM dummytable
where minagegrp <=9
or maxagegrp >= 7 

Upvotes: 2

Related Questions