469,919 Members | 2,135 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,919 developers. It's quick & easy.

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

seshu
156 100+
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
4 1186
r035198x
13,262 8TB
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
156 100+
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
5,821 Expert 4TB
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
156 100+
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.

Similar topics

5 posts views Thread by 73blazer | last post: by
2 posts views Thread by Andy S. | last post: by
1 post views Thread by Matik | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.