Ok, what I want to do is find out the number of rows in a table. The most
obvious solution is to do something like the following:
$sql = "SELECT blah FROM blah WHERE 1";
$result = mysql_query($sq l, $db);
$num = mysql_num_rows( $result);
If you have a large table, to me that seems like it would be a system hog if
all you want is the number of rows but not the data. I'm not sure if using
mysql_unbuffere d_query() would solve this, would it?
Basically my question is this: what is the fastest, most effecient way to
just find out the number of rows in a table?
Thank you. 3 24097
On Mon, 28 Jul 2003 14:22:40 GMT, "Xizor" <no**@nope.co m> wrote: Ok, what I want to do is find out the number of rows in a table. The most obvious solution is to do something like the following:
$sql = "SELECT blah FROM blah WHERE 1"; $result = mysql_query($sq l, $db); $num = mysql_num_rows( $result);
That is the worst possible way, fetching the entire contents of the
table off disk, into memory, transferred over to the client, and then
ignored.
If you have a large table, to me that seems like it would be a system hog if all you want is the number of rows but not the data. I'm not sure if using mysql_unbuffer ed_query() would solve this, would it?
No, because mysql_num_rows becomes unavailable, as the database
doesn't know how many rows are in the result set - it starts
transferring them to the client before they've all been read out of
the database.
Basically my question is this: what is the fastest, most effecient way to just find out the number of rows in a table?
If you want to count the number of rows, use COUNT, which returns a
single row with the number of rows matched.
MySQL keeps total number of rows stored in a table as part of the
metadata for a table, so 'select count(*) from tab' doesn't even
access the table.
And if you have a WHERE clause, then you avoid fetching all the data
that you don't want if you use COUNT; the database just counts the
number of matching rows without reading the data itself.
--
Andy Hassall (an**@andyh.co. uk) icq(5747695) ( http://www.andyh.co.uk)
Space: disk usage analysis tool ( http://www.andyhsoftware.co.uk/space)
use
select count(*) from blah;
It will return just the number.
"Xizor" <no**@nope.co m> wrote in message
news:QkaVa.1471 37$GL4.37783@rw crnsc53... Ok, what I want to do is find out the number of rows in a table. The most obvious solution is to do something like the following:
$sql = "SELECT blah FROM blah WHERE 1"; $result = mysql_query($sq l, $db); $num = mysql_num_rows( $result);
If you have a large table, to me that seems like it would be a system hog
if all you want is the number of rows but not the data. I'm not sure if using mysql_unbuffere d_query() would solve this, would it?
Basically my question is this: what is the fastest, most effecient way to just find out the number of rows in a table?
Thank you.
In article <%Z************ ********@newssr v26.news.prodig y.com>,
"s a n j a y" <so*****@somewh ere.com> wrote: use
select count(*) from blah;
It will return just the number.
FYI, if the original poster has learned SQL mostly through PHP books,
etc., he might wanna look into some SQL-specific books. I did, and was
surprised at how many things one can do with the SQL query itself (like
the above!).
--
Floydian Slip(tm) - "Broadcasti ng from the dark side of the moon"
Random Precision Productions(tm)
67 Union St. #2D, Winooski, Vt. 05404-1948 USA
Sundays, 7-8 pm - Champ 101.3 FM, Colchester; 102.1 FM, Randolph, Vt. cc*@floydiansli p.com - AIM: RandomPrec - www.floydianslip.com This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Phil Powell |
last post by:
Relevancy scores are normally defined by a MySQL query on a table that
has a fulltext index. The rules for relevancy scoring will exclude
certain words due to their being too short (minimum default is 4
letters).
This is the Fed. Everything is a TLA (three-letter acronym).
Therefore, since I'm building a PORTABLE web application, changing
MySQL's default settings for fulltext index querying is completely
undoable and unrealistic, so...
|
by: Phil Powell |
last post by:
The table already has a fulltext index and from there I can use the
MySQL fulltext search query to get results as well as the relevancy
score.
The problem I have is that MySQL has a default setting whereby the
minimum amount of characters is 4 for a search. Being that we're
government and full of TLA (three-letter acronyms), that is not
practical, and furthermore, the app I'm building must be fully
portable, so having MySQL tweaked...
|
by: Tony Clarke |
last post by:
Hi,
Just a quick question about performance with MySQL & PHP. If I had a table
in a MySQL database with about 100,000 records in it and I need to find the
last record is there a quick way to do this, other than going through the
whole database to find the last record? Would the amount of records in the
table cause major performance problems?
For example, if I had a html form that people used to log something and
needed to display a...
|
by: knoak |
last post by:
Hi there,
I have a small question:
I have a table with lots of rows in it. Of course all have a different id,
but each can be assigned to a certain category. Categories correspond
with 1 - 10.
So a row looks like this: 'unique id | 4'
What i want is to do a count how much rows belong to a certain category.
|
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 version of this document can be found at:
http://prdownloads.sourceforge.net/souptonuts/README_mysql.txt?download
| |
by: Sven Reifegerste |
last post by:
Hi,
i have a table with INT columns id,key,b1,b2,c1,c2, having 1.500.000
rows. 'key' and 'id' are indexed (Kardinality 385381) and id
(Kardinality 1541525).
Performing a
SELECT * FROM table WHERE key IN (10,11,12) OR key BETWEEN 20000 AND
28000 AND b1<4500000 AND b2>3954545 AND c1<4543554 AND c2>4400000
|
by: elyob |
last post by:
Hi,
I'm looking at storing snippets of details in MySQL about what credit cards
a business excepts. Rather than have a whole column for Visa, another for
Amex etc ... I am looking at having a column called payment types and
inserting multiple codes ... e.g. ViAmBcCa
Is this a good way of doing things? To me it'd be a lot cleaner and limit
amount of Db work to be done. Is this a sensible way in your opinion? What's
the best way of...
|
by: moller |
last post by:
Im looking in to the possibility of moving from mySQL to
an access database.
My reasons are:
(1) Database is single user.
(2) Database local on users PC.
(3) Database has only 8 tables where 4 are filled at database creation
with aprox 20 rows each and are never added to after that.
(4) Database grows with ca 6000 rows/week.
(5) No data is ever deleted, exept... (6)
|
by: Atli |
last post by:
This is an easy to digest 12 step guide on basics of using MySQL. It's a great refresher for those who need it and it work's great for first time MySQL users.
Anyone should be able to get through this without much trouble. Programming knowledge is not required.
Index
What is SQL?
Why MySQL?
Installing MySQL.
Using the MySQL command line interface
|
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,...
|
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...
| |
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...
|
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,...
|
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...
|
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...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |