473,665 Members | 2,774 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Get total number of results but still use LIMIT?

Is there a (better) way to get the toal number of results from a query
but still limit them with a LIMIT clause. For example, in a Google
search result, it displays 1-100 of 10,000,000 results. Do they hit
the database once for results, and again for a total count or is it
all in one query? Thanks -Nick
Jul 20 '05 #1
5 2675
interesting.

I've noticed that if the amount is a big number, google gives only a approx
number.

And sometimes a small amount is not accurate to the real result number that
google returns.

I personal believe there's some stat in their index.

Waiting for more info here with Nick :-)
ccton
--
www.vicdir.com
"Nick" <nb********@hot mail.com> ????
news:ce******** *************** ***@posting.goo gle.com...
Is there a (better) way to get the toal number of results from a query
but still limit them with a LIMIT clause. For example, in a Google
search result, it displays 1-100 of 10,000,000 results. Do they hit
the database once for results, and again for a total count or is it
all in one query? Thanks -Nick

Jul 20 '05 #2
Nick wrote:
Is there a (better) way to get the toal number of results from a query but still limit them with a LIMIT clause. For example, in a Google
search result, it displays 1-100 of 10,000,000 results. Do they hit
the database once for results, and again for a total count or is it
all in one query? Thanks -Nick


Don’t know what google is doing, but e.g. PHPBB bulletin board queries
completely, and then only shows the top xx results. So it does not do
a limit.

You can easily do a benchmark between:
(a) doing two queries, one using a limit
(b) using a single query, and then showing the top xx results

Otherwise, I don’t believe what you asking is possible.

--
http://www.dbForumz.com/ This article was posted by author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbForumz.com/mySQL-total-...ict125578.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=432463
Jul 20 '05 #3
For right now im doing...

SELECT
(SELECT count(id) FROM table1) as totalResults,
id,
field1,
field2

FROM table1

I guess this works for my situation. -Nick
Jul 20 '05 #4
Nick wrote:
Is there a (better) way to get the toal number of results from a query but still limit them with a LIMIT clause. For example, in a Google
search result, it displays 1-100 of 10,000,000 results. Do they hit
the database once for results, and again for a total count or is it
all in one query? Thanks -Nick


Don’t know what google is doing, but e.g. PHPBB bulletin board queries
completely, and then only shows the top xx results. So it does not do
a limit.

You can easily do a benchmark between:
(a) doing two queries, one using a limit
(b) using a single query, and then showing the top xx results

Otherwise, I don’t believe what you asking is possible.

--
http://www.dbForumz.com/ This article was posted by author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbForumz.com/mySQL-total-...ict125578.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=432463
Jul 20 '05 #5
For right now im doing...

SELECT
(SELECT count(id) FROM table1) as totalResults,
id,
field1,
field2

FROM table1

I guess this works for my situation. -Nick
Jul 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2394
by: Wahoo | last post by:
Another question,my teacher gave me a code for generate a random number from 1 - range, but I can't made it work, where is the problem? Thanks!!
3
1544
by: zen | last post by:
PHP Mysql limit the result to 5 I can display the 5 results using a do & while which it ok. I want to list the total or all the results without using a do or while this is so I can combine the results and remove duplicate words from the total results I.E.
3
7795
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 same query with a count(*) to know how many pages I will get (number total of rows/ X). The problem is my query is very slow (maybe 5s) because there is much
7
12067
by: Egor Shipovalov | last post by:
I'm implementing paging through search results using cursors. Is there a better way to know total number of rows under a cursor than running a separate COUNT(*) query? I think PostgreSQL is bound to know this number after the first FETCH, isn't it? On a side note, why queries using LIMIT are SO terribly slow, compared to cursors and sometimes even ones without LIMIT? Shouldn't LIMIT be internally implemented using cursor mechanism then?...
0
5776
by: D. Dante Lorenso | last post by:
I need to know that original number of rows that WOULD have been returned by a SELECT statement if the LIMIT / OFFSET where not present in the statement. Is there a way to get this data from PG ? SELECT ... ; ----> returns 100,000 rows
15
1778
by: Hexman | last post by:
Hello All, How do I limit the number of detail records selected in a Master-Detail set using SQL? I want to select all master records for a date, but only the first 3 records for the details (based on the primary key of the detail record). I've been trying with "TOP 3", but can't get anywhere. Using Access 2000. Something like: SELECT t1.*, TOP 3 t2.*
7
3466
by: itm | last post by:
I have a mail out to send to a group of owners with multiple accounts. I want to limit the number of accounts that print on the first page to 20. I want remaining accounts to print on a second page. Is there a way to accomplish this? Thanks so much for your help!
1
1365
by: ZiggyShort | last post by:
I need to summate across a number of line items over a group of invoices, then round down on an invoice by invoice basis to the nearest penny. I would then like to get a total of THOSE rounded values. Does my sql need to return the items, and i then manually summate these values by reading each one by one, or can I do this in the sql. Remember, I still need to round on an invoice by invoice basis. My sql which returns rounded invoice totals...
2
3404
by: alwaali | last post by:
Hi I need help please This is my project and i need a help to solve it with you A page of text is to be read and analyzed to determine number of occurrences and locations of different words. The results of the analysis are to be stored in a suitable data structure. The main task in this project is to design a suitable ADT (call it WAnalysis) to store the results and enable the following operations to be performed as fast as possible:...
0
8438
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8348
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8863
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8779
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8549
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8636
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7376
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6187
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4186
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...

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.