473,408 Members | 1,976 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,408 software developers and data experts.

have a query with 4 selects in union and want to use count() and limit on the whole

mikek12004
200 100+
with one query I would something like this
Expand|Select|Wrap|Line Numbers
  1. SELECT COUNT(id) AS numrows FROM pelates where owned='112';
  2.  
to get the number of results and this
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM pelates where owned='122' LIMIT 10,20
  2.  
to get the subset I need, but now I have a union of 4 selects and I want the count of the whole and the limit to be applied to the whole results also any ideas?
Nov 30 '09 #1
1 1427
SLauren
60
You can use "SQL_CALC_FOUND_ROWS" to get the number of rows being resulted out of the query executed and after executing the query assign "FOUND_ROWS()" to your out parameter which will hold the number of records resulted. You can use the LIMIT keyword on the whole query.

For example:

Expand|Select|Wrap|Line Numbers
  1. SELECT SQL_CALC_FOUND_ROWS DISTINCT ID,Name FROM Table1 WHERE <Condition>
  2. UNION
  3. SELECT DISTINCT ID,Name FROM Table2 WHERE <Condition> LIMIT 1,50;
  4.  
  5. SET outParam := FOUND_ROWS();
Hope this could help.

Thanks,
Lauren
Nov 30 '09 #2

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

Similar topics

0
by: Mike Chirico | last post by:
Interesting Things to Know about MySQL Mike Chirico (mchirico@users.sourceforge.net) Copyright (GPU Free Documentation License) 2004 Last Updated: Mon Jun 7 10:37:28 EDT 2004 The latest...
5
by: Stephen Miller | last post by:
Hi, I am trying to add a staggered running total and average to a query returning quarterly CPI data. I need to add 4 quarterly data points together to calculate a moving 12-month sum (YrCPI),...
3
by: Paradigm | last post by:
I am using Access 2K as a front end to a MYSQL database. I am trying to run a Union query on the MYSQL database. The query is (much simplified) SELECT as ID from faxdata UNION SELECT as ID ...
2
by: serge | last post by:
/* This is a long post. You can paste the whole message in the SQL Query Analyzer. I have a scenario where there are records with values pointing to wrong records and I need to fix them using an...
3
by: krystoffff | last post by:
Hi I would like to paginate the results of a query on several pages. So I use a query with a limit X offset Y to display X results on a page, ok. But for the first page, I need to run the...
2
by: Justin Koivisto | last post by:
In PHP, I do the following (pseudo code for clarity)... Query: SELECT distinct(web_contacts.zip) FROM web_contacts WHERE web_contacts.zip <> '' Query: SELECT DISTINCT(contacts.zip) FROM contacts...
15
by: laurenq uantrell | last post by:
Wondering if there is a physical or realistic limitation to the number of UNION statements I can create in a query? I have a client with approx 250 tables - the data needs to be kept in seperate...
1
by: ramprat | last post by:
Hi, I'm trying to use the results from a select query as a way to limit the records that I update with my update query and it seems like it should work but I keep getting a "Operation must use an...
3
by: mzahid | last post by:
I have 3 tables student(s_id,s_name),course(c_id,c_name) and student_course(s_id(FK),c_id(FK)). I would Like to select those students Name who have enrolled more then and equal to 3 courses. What...
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?
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.