Here i want to select questions with two different difficulty from same table. I am using query :
readAllQuestions = [NSString stringWithFormat: @"SELECT * FROM tbl_questions WHERE difficulty IN(1,3) AND approved = 1"];
Its working. Now i want to limit the questions to 100 and it includes 50 questions with difficulty 1 and other 50 with difficulty 3. Using LIMIT
only give first 100 questions.
How to do this without using two different queries?? Please help..
You can do so with subselects: (assuming the primary key is called 'id')
SELECT * FROM tbl_questions WHERE (id IN (SELECT id FROM tbl_questions WHERE difficulty = 1 LIMIT 0,50) OR id IN (SELECT id FROM tbl_questions WHERE difficulty = 3 LIMIT 0,50)) AND approved = 1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With