By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,156 Members | 950 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,156 IT Pros & Developers. It's quick & easy.

can I write only one select stmt insted of three diff please see the Querys bellow

seshu
100+
P: 156
Hi everybody
Presently Iam write three select statements with diff where and limt conditions but the select stmt in them is same insted of that can i write only one direct stmt and the queries are like this

1)select question,opt1,opt2,opt que_level from questions where que_level=1 limit 4-------here i want only 4 questions whose level is 1 among 100 questions

2)select question,opt1,opt2,opt que_level from questions where que_level=2 limit 5-------here i want only 5 questions whose level is 2 among 100 questions

3)select question,opt1,opt2,opt que_level from questions where que_level=3 limit 7-------here i want only 7 questions whose level is 3 among 100 questions

Please help me out

Regards
Seshu
Jun 20 '07 #1
Share this Question
Share on Google+
4 Replies


10K+
P: 13,264
Hi everybody
Presently Iam write three select statements with diff where and limt conditions but the select stmt in them is same insted of that can i write only one direct stmt and the queries are like this

1)select question,opt1,opt2,opt que_level from questions where que_level=1 limit 4-------here i want only 4 questions whose level is 1 among 100 questions

2)select question,opt1,opt2,opt que_level from questions where que_level=2 limit 5-------here i want only 5 questions whose level is 2 among 100 questions

3)select question,opt1,opt2,opt que_level from questions where que_level=3 limit 7-------here i want only 7 questions whose level is 3 among 100 questions

Please help me out

Regards
Seshu
Perhaps you can use a stored procedure ...
Jun 20 '07 #2

seshu
100+
P: 156
I heard that in mysql 4.1 stored procedures dont work it seems more over i don no how to write a stored procedure so can any one help me with some other way or this is the only way

Regards
Seshu
Jun 20 '07 #3

pbmods
Expert 5K+
P: 5,821
Heya, Seshu.

The only way you could do this effectively would be to use the UNION keyword.

MySQL would still have to make three queries, but it would combine them into one result set.
Jun 22 '07 #4

seshu
100+
P: 156
Thank you you have solved my problem and i can use this query and change many apps
thank you
Jun 22 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.