473,388 Members | 1,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

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 1353
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

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

Similar topics

5
by: 73blazer | last post by:
Hello, I'm looking for a SQL syntax to put a variable name into the from clause. Specifically I have a colume in a table that is table name, and I want to use that result in the from clause in a...
2
by: Andy S. | last post by:
Hi, I'm trying to declare and use temporary tables. I have written the following code in Java. Creating the tablespace (i can see the tablespace created using the Control Center), the temporary...
7
by: Gucci | last post by:
<?php /** * check ine year is a leap year, and return the month day array * * @param int $year **the year must bigger than zero** * @return array */ function is_leap_year($year){...
1
by: Matik | last post by:
Hello Everybody, I have a problem, with select stmt: SELECT TOP 15 * FROM oaVIEW_MainData AS TOP_VIEW, oaLanguageData_TAB AS RwQualifierJoin with (nolock) WHERE (c_dateTime>='2007.01.10...
0
by: jad2006 | last post by:
i created CREATE PROCEDURE SP_STMT_STMTRETRIEVE10(IN p_client_id varchar(32) ,IN p_TIN varchar(32)) P1: BEGIN DECLARE p_customer_id varchar(32); DECLARE stmt VARCHAR(100); DECLARE cursor1...
9
by: asenthil | last post by:
Hai to all,, i had to tried to retrive and write a single row to a file from the database.. But dont know to write all the retrived rows to a file from the database.. how to do that... ...
1
by: Kingsly | last post by:
How to read "stmt" column of "sysibm.syspackstmt" table in a readable format? select stmt from sysibm.syspackstmt where name like 'MYPROC1'; I was expecting the stored procedure statements as...
5
by: andi | last post by:
Hello, I created a report in Acess2000 and now it repeats itself three times. At first I thought its a problem with the page margins but that would mean that empty or almost empty pages would...
8
by: yrrah | last post by:
Hello, i've a problem regarding the select stmt inside the stored procedure. Here's my code: DELIMITER $$ DROP PROCEDURE IF EXISTS `p`.`getNames`$$ CREATE PROCEDURE `p`.`getNames`(q...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.