473,473 Members | 1,523 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How can I retrieve records and a total count of the records - MySQL

37 New Member
If I write:

SELECT * FROM table_name WHERE date BETWEEN "2014/07/01" AND "2014/07/04"

I get 4 records returned which is what I want. But I also want the total number of records which in this case is 4, but if I write:

SELECT *, count(*) AS total FROM table_name WHERE date BETWEEN "2014/07/01" AND "2014/07/04"

It displays total 4, but only one record.

How can I display all 4 records and "total 4"?
Jul 4 '14 #1
1 1240
Luuk
1,047 Recognized Expert Top Contributor
The short answer is:
Expand|Select|Wrap|Line Numbers
  1. SELECT t.*, (SELECT count(*) 
  2.              FROM table_name
  3.              WHERE date BETWEEN "2014/07/01" AND "2014/07/04") as Count
  4. FROM table_name t
  5. WHERE t.date BETWEEN "2014/07/01" AND "2014/07/04" 
  6.  
Jul 4 '14 #2

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

Similar topics

1
by: Tracey | last post by:
in my procedure, I want to count the number of rows that have errored during an insert statement - each row is evaluated using a cursor, so I am processing one row at a time for the insert. My...
2
by: Ryan | last post by:
Access97 I hope someone out there can help. This is driving me crazy. Basically, I am trying to recreate VBA's built in navigation feature (The one that allows you to move first, next,...
2
by: Rich | last post by:
Hello, Is there a way to capture the Records Affected count when performing a table Update on a Sql Server table using a DataAdapter? How is this done? Thanks, Rich
1
by: JustinCarmony | last post by:
I'm using a DataAdapter to fill a DataSet to display a list of items in a custom way. I'm not using the GridView or any server controls like that. This is my code: <code> SqlConnection sqlConn...
5
by: Soccer5 | last post by:
Trying to Count records on a report that meet a certain criteria. Have a text box in the Report Footer that has the following in the Control Source: =Count(="S") This does not work. It...
1
by: crystalgal | last post by:
Help. I am using Excel to enter in daily numbers in worksheet 2. I want to use vb (w/in excel) to create a command button in worksheet 1. I want to enter a date in a cell and click the command...
4
by: jessiK | last post by:
Pls help! I'm new to PHP and MySQL and I'm having a problem when working with my database (I am using IIS6). When using PHP I can connect to the database without any problems, I can even add new...
9
by: john20 | last post by:
Hi All, How can i find the total 'Count' of a particular character's occurance in a string. means i want to find the count of '<' in a string. can you please help to find that. Thanks
1
Fary4u
by: Fary4u | last post by:
code works fine it's counts the records but not bring updated record? is there any other way to count records ? Set rs = Server.CreateObject("ADODB.Recordset") strSQL = "SELECT...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...
1
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...
1
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.