

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How can I select rows which fall on a specific day of week in MySQL?
For specific day of week, use DAYOFWEEK().
Let us first create a table −
mysql> create table DemoTable785 ( CustomerId int NOT NULL AUTO_INCREMENT PRIMARY KEY, CustomerName varchar(100), ShoppingDate date ); Query OK, 0 rows affected (0.61 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable785(CustomerName,ShoppingDate) values('Chris','2019-07-03'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable785(CustomerName,ShoppingDate) values('Robert','2019-07-01'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable785(CustomerName,ShoppingDate) values('David','2019-07-06'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable785(CustomerName,ShoppingDate) values('Carol','2019-07-19'); Query OK, 1 row affected (0.19 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable785;
This will produce the following output -
+------------+--------------+--------------+ | CustomerId | CustomerName | ShoppingDate | +------------+--------------+--------------+ | 1 | Chris | 2019-07-03 | | 2 | Robert | 2019-07-01 | | 3 | David | 2019-07-06 | | 4 | Carol | 2019-07-19 | +------------+--------------+--------------+ 4 rows in set (0.00 sec)
Following is the query to select rows which fall on a specific day of week −
mysql> select *from DemoTable785 where DAYOFWEEK(ShoppingDate)=2;
This will produce the following output -
+------------+--------------+--------------+ | CustomerId | CustomerName | ShoppingDate | +------------+--------------+--------------+ | 2 | Robert | 2019-07-01 | +------------+--------------+--------------+ 1 row in set (0.00 sec)
- Related Questions & Answers
- How select specific rows in MySQL?
- MySQL query to select rows older than a week?
- In MySQL, how we can compute date by providing the year, week number and day of the week? day of the week?
- Select specific rows in a range with MySQL?
- Get the week number in MySQL for day of week?
- How can I programmatically select a specific subplot in Matplotlib?
- Crontab day of the week syntax on Linux
- How can I add a new column which counts the number of rows as serial number in MySQL?
- How do I SELECT none of the rows and columns in MySQL?
- How can I loop through all rows of a table in MySQL?
- Day of the Week in C++
- How to select only 3 ordered rows on a MySQL table?
- Get Day Number of Week in Java
- Which gods or goddesses are associated with which day of the week as per Hindu mythology?
- Select last day of current year in MySQL?
Advertisements