Re: Count Rows?
On Wed, Jul 02, 2003 at 10:57:18AM -0500, Roy W wrote: Is there a simple MySQL command that will give a Row Count (# of records) WITHOUT running a select (huge database) If it's a MyISAM table, just run a SELECT COUNT(*) FROM table_name. It's really efficient. Try it. :-) -- Jeremy D. Zawodny | Perl, Web, MySQL, Linux Magazine, Yahoo! [EMAIL PROTECTED] | http://jeremy.zawodny.com/ MySQL 4.0.13: up 31 days, processed 979,861,677 queries (357/sec. avg) -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
RE: Count Rows?
If your table is MyISAM, then SELECT COUNT(*) FROM tablename Will return a rowcount without a major performance hit as the rowcount is stored and a table scan is not needed. Regards, Mike Hillyer www.vbmysql.com -Original Message- From: Roy W [mailto:[EMAIL PROTECTED] Sent: Wednesday, July 02, 2003 9:57 AM To: [EMAIL PROTECTED] Subject: Count Rows? Is there a simple MySQL command that will give a Row Count (# of records) WITHOUT running a select (huge database) Thanks! Roy -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
Re: count rows
Here's a nice MySQL simple returning records query question! I want to return a staement saying 'number of records shave been found' for your selection. so presumably this is a simple row count based on the the returning recordset? Andrew Either with PHP or C you can use mysql_num_rows() Bye! - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail [EMAIL PROTECTED] To unsubscribe, e-mail [EMAIL PROTECTED] Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
Re: count rows
Here's a nice MySQL simple returning records query question! I want to return a staement saying 'number of records shave been found' for your selection. so presumably this is a simple row count based on the the returning recordset? Andrew Either with PHP or C you can use mysql_num_rows() In perl:$numRows = $sth-rows; Note the following warning from the DBI man page: Generally, you can only rely on a row count after a non-SELECT execute (for some specific operations like UPDATE and DELETE), or after fetching all the rows of a SELECT statement. Bye! William R. Mussatto, Senior Systems Engineer Ph. 909-920-9154 ext. 27 FAX. 909-608-7061 - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail [EMAIL PROTECTED] To unsubscribe, e-mail [EMAIL PROTECTED] Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
Re: Count Rows in two tables
If you know the primary keys of the two tables, it may be done as follows: select count(distinct t1.pk1) + count(distinct t2.pk2) from t1,t2; where - pk1 is the primary key column name of table t1 and pk2 is the primary key column name of table t2. SB - Original Message - From: Rick Baranowski [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, November 13, 2002 8:39 AM Subject: Re: Count Rows in two tables Please forgive me I am new to mySQL, could you give me an example of how I would do this? The two tables are users and staff Thanks Rick - Original Message - From: Murad Nayal [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Tuesday, November 12, 2002 6:58 PM Subject: Re: Count Rows in two tables Alan McDonald wrote: You can't count the join? Alan if you count the (unqualified) join you'll end up with the product of the two table counts. Murad -Original Message- From: Rick Baranowski [mailto:rickb;baranconsulting.com] Sent: Wednesday, 13 November 2002 12:10 To: [EMAIL PROTECTED] Subject: Count Rows in two tables Hello all, Does anybody have a SQL string to count the rows in two different tables and give you a total number of rows? I have been trying to find an answer for a couple of days and seems like a simple string. Thank you Rick - - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail [EMAIL PROTECTED] To unsubscribe, e-mail [EMAIL PROTECTED] Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail [EMAIL PROTECTED] To unsubscribe, e-mail [EMAIL PROTECTED] Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail [EMAIL PROTECTED] To unsubscribe, e-mail [EMAIL PROTECTED] Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
Re: Count Rows in two tables
Thank you for the response. It looks like that worked! I am going to try it on the webpage now. I will let everybody know if this works. Thanks Rick PS. to everyone else I want to say thanks. I have run the ones that you have sent but always came up with an error. If you want me to send you the error let me know and I will send it to you. Thanks again - Original Message - From: Shyamal Banerjee [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, November 13, 2002 4:29 AM Subject: Re: Count Rows in two tables If you know the primary keys of the two tables, it may be done as follows: select count(distinct t1.pk1) + count(distinct t2.pk2) from t1,t2; where - pk1 is the primary key column name of table t1 and pk2 is the primary key column name of table t2. SB - Original Message - From: Rick Baranowski [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, November 13, 2002 8:39 AM Subject: Re: Count Rows in two tables Please forgive me I am new to mySQL, could you give me an example of how I would do this? The two tables are users and staff Thanks Rick - Original Message - From: Murad Nayal [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Tuesday, November 12, 2002 6:58 PM Subject: Re: Count Rows in two tables Alan McDonald wrote: You can't count the join? Alan if you count the (unqualified) join you'll end up with the product of the two table counts. Murad -Original Message- From: Rick Baranowski [mailto:rickb;baranconsulting.com] Sent: Wednesday, 13 November 2002 12:10 To: [EMAIL PROTECTED] Subject: Count Rows in two tables Hello all, Does anybody have a SQL string to count the rows in two different tables and give you a total number of rows? I have been trying to find an answer for a couple of days and seems like a simple string. Thank you Rick - - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail [EMAIL PROTECTED] To unsubscribe, e-mail [EMAIL PROTECTED] Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail [EMAIL PROTECTED] To unsubscribe, e-mail [EMAIL PROTECTED] Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail [EMAIL PROTECTED] To unsubscribe, e-mail [EMAIL PROTECTED] Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail [EMAIL PROTECTED] To unsubscribe, e-mail [EMAIL PROTECTED] Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
RE: Count Rows in two tables
You can't count the join? Alan -Original Message- From: Rick Baranowski [mailto:rickb;baranconsulting.com] Sent: Wednesday, 13 November 2002 12:10 To: [EMAIL PROTECTED] Subject: Count Rows in two tables Hello all, Does anybody have a SQL string to count the rows in two different tables and give you a total number of rows? I have been trying to find an answer for a couple of days and seems like a simple string. Thank you Rick - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail [EMAIL PROTECTED] To unsubscribe, e-mail [EMAIL PROTECTED] Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail [EMAIL PROTECTED] To unsubscribe, e-mail [EMAIL PROTECTED] Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
Re: Count Rows in two tables
On 11/12/02 5:36 PM, Alan McDonald [EMAIL PROTECTED] wrote: You can't count the join? Alan Hello all, Does anybody have a SQL string to count the rows in two different tables and give you a total number of rows? I have been trying to find an answer for a couple of days and seems like a simple string. Thank you Rick I guess he wants something like: SELECT SUM(COUNT(t1.*) , COUNT(t2.*)) FROM table1 t1, table2; Which obviously doesn't work. Maybe once we have subselects we can do it in one query: /h - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail [EMAIL PROTECTED] To unsubscribe, e-mail [EMAIL PROTECTED] Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
Re: Count Rows in two tables
Does it have to be in a single query. You could use a Union query and then total the results in your program. Select Count(Field1) From Table1 Union Select Count(Field1) From Table2; Rick Baranowski [EMAIL PROTECTED] 11/12/02 5:10:14 PM Hello all, Does anybody have a SQL string to count the rows in two different tables and give you a total number of rows? I have been trying to find an answer for a couple of days and seems like a simple string. Thank you Rick - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail [EMAIL PROTECTED] To unsubscribe, e-mail [EMAIL PROTECTED] Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail [EMAIL PROTECTED] To unsubscribe, e-mail [EMAIL PROTECTED] Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
Re: Count Rows in two tables
Alan McDonald wrote: You can't count the join? Alan if you count the (unqualified) join you'll end up with the product of the two table counts. Murad -Original Message- From: Rick Baranowski [mailto:rickb;baranconsulting.com] Sent: Wednesday, 13 November 2002 12:10 To: [EMAIL PROTECTED] Subject: Count Rows in two tables Hello all, Does anybody have a SQL string to count the rows in two different tables and give you a total number of rows? I have been trying to find an answer for a couple of days and seems like a simple string. Thank you Rick - - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail [EMAIL PROTECTED] To unsubscribe, e-mail [EMAIL PROTECTED] Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
RE: Count Rows in two tables
Ah, yes - sorry Alan -Original Message- From: [EMAIL PROTECTED] [mailto:murad;godel.bioc.columbia.edu]On Behalf Of Murad Nayal Sent: Wednesday, 13 November 2002 12:58 Cc: [EMAIL PROTECTED] Subject: Re: Count Rows in two tables Alan McDonald wrote: You can't count the join? Alan if you count the (unqualified) join you'll end up with the product of the two table counts. Murad -Original Message- From: Rick Baranowski [mailto:rickb;baranconsulting.com] Sent: Wednesday, 13 November 2002 12:10 To: [EMAIL PROTECTED] Subject: Count Rows in two tables Hello all, Does anybody have a SQL string to count the rows in two different tables and give you a total number of rows? I have been trying to find an answer for a couple of days and seems like a simple string. Thank you Rick - - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail [EMAIL PROTECTED] To unsubscribe, e-mail [EMAIL PROTECTED] Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail [EMAIL PROTECTED] To unsubscribe, e-mail [EMAIL PROTECTED] Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
Re: Count Rows in two tables
Please forgive me I am new to mySQL, could you give me an example of how I would do this? The two tables are users and staff Thanks Rick - Original Message - From: Murad Nayal [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Tuesday, November 12, 2002 6:58 PM Subject: Re: Count Rows in two tables Alan McDonald wrote: You can't count the join? Alan if you count the (unqualified) join you'll end up with the product of the two table counts. Murad -Original Message- From: Rick Baranowski [mailto:rickb;baranconsulting.com] Sent: Wednesday, 13 November 2002 12:10 To: [EMAIL PROTECTED] Subject: Count Rows in two tables Hello all, Does anybody have a SQL string to count the rows in two different tables and give you a total number of rows? I have been trying to find an answer for a couple of days and seems like a simple string. Thank you Rick - - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail [EMAIL PROTECTED] To unsubscribe, e-mail [EMAIL PROTECTED] Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail [EMAIL PROTECTED] To unsubscribe, e-mail [EMAIL PROTECTED] Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php