
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
Search records on the basis of date in MySQL?
Let us first create a table -
mysql> create table DemoTable732 ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, PassengerId int, PassengerName varchar(100), PassengerAge int, PassengerTravelDatetime datetime ); Query OK, 0 rows affected (0.67 sec)
Insert some records in the table using insert command -
mysql> insert into DemoTable732(PassengerId,PassengerName,PassengerAge,PassengerTravelDatetime) values(110,'Chris',25,'2019-07-23 12:45:56'); Query OK, 1 row affected (0.40 sec) mysql> insert into DemoTable732(PassengerId,PassengerName,PassengerAge,PassengerTravelDatetime) values(120,'Robert',24,'2019-07-21 11:05:00'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable732(PassengerId,PassengerName,PassengerAge,PassengerTravelDatetime) values(120,'Sam',26,'2019-07-21 11:05:00'); Query OK, 1 row affected (0.30 sec)
Display all records from the table using select statement -
mysql> select *from DemoTable732;
This will produce the following output -
+----+-------------+---------------+--------------+-------------------------+ | Id | PassengerId | PassengerName | PassengerAge | PassengerTravelDatetime | +----+-------------+---------------+--------------+-------------------------+ | 1 | 110 | Chris | 25 | 2019-07-23 12:45:56 | | 2 | 120 | Robert | 24 | 2019-07-21 11:05:00 | | 3 | 120 | Sam | 26 | 2019-07-21 11:05:00 | +----+-------------+---------------+--------------+-------------------------+ 3 rows in set (0.00 sec)
Here is the query to simple SELECT COUNT SQL query error -
mysql> select count(Id) from DemoTable732 where PassengerId=120 and date(PassengerTravelDatetime)='2019-07-21';
This will produce the following output -
+-----------+ | count(Id) | +-----------+ | 2 | +-----------+ 1 row in set (0.00 sec)
- Related Articles
- How to display the day name on the basis of Date of Birth records in MySQL?
- Fetch records on the basis of LastName using MySQL IN()
- Select items based on value first, then order on the basis of date for rest of the records in MySQL
- Display records on the basis of key-value pairs in MySQL
- Fastest way to search for a date from the date records in MySQL
- Select records from a table on the basis of keywords in MySQL
- MySQL query to ORDER BY records on the basis of modulus result
- Perform MySQL UPDATE on the basis of DATE value in another column
- Select and filter the records on month basis in a MySQL table?
- Add a column count in a MySQL query on the basis of last name records?
- MySQL query to display records on the basis of conditions IS NULL OR !=1;?
- Comparison of varchar date records from the current date in MySQL
- Fetching records from a table with NULL and other values on the basis of conditions in MySQL
- Need to populate autocomplete with records on the basis of first and last name of schools in MySQL?
- MySQL query to select records from a table on the basis of a particular month number?

Advertisements