- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 4378 Articles for MySQL
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
280 Views
For year and month date fetching, you can use YEAR() and MONTH() function in MySQL. Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, ShippingDate datetime ); Query OK, 0 rows affected (0.48 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(ShippingDate) values('2019-01-31'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable(ShippingDate) values('2018-12-01'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable(ShippingDate) values('2019-06-02'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable(ShippingDate) values('2019-11-18'); Query OK, 1 row ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
330 Views
For this, you can use multiple OR. Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, FirstName varchar(10), LastName varchar(10), Age int, CountryName varchar(10) ); Query OK, 0 rows affected (0.58 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(FirstName, LastName, Age, CountryName) values('John', 'Smith', 21, 'US'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable(FirstName, LastName, Age, CountryName) values('Carol', 'Taylor', 22, 'AUS'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable(FirstName, LastName, Age, CountryName) values('David', ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
1K+ Views
For this, use the aggregate function COUNT() along with GROUP BY. Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Value int ); Query OK, 0 rows affected (0.74 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Value) values(976); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(Value) values(67); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable(Value) values(67); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable(Value) values(1); Query OK, 1 row affected (0.27 sec) mysql> ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
294 Views
The query SELECT NOW() gives the current date as well as current time. If you want only current date, use only CURDATE(). Following is the syntax for datetime −SELECT NOW();The syntax for only date.SELECT CURDATE();Let us now implement the above syntax −Case 1 : If you want both current date and time −mysql> SELECT NOW();Output+-----------------------+ | NOW() | +-----------------------+ | 2019-06-02 15 :30 :39 | +-----------------------+ 1 row in set (0.00 sec)Case 2 : If you want the current date only −mysql> SELECT CURDATE();Output+------------+ | CURDATE() | +------------+ | 2019-06-02 | +------------+ 1 row in set (0.00 sec)
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
626 Views
To add two weeks to a date in MySQL, use DATE_ADD() −insert into yourTableName(yourColumnName) values(date_add(now(), interval 2 week));Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, ShippingDate datetime ); Query OK, 0 rows affected (0.62 sec)Following is the query to get the current date −mysql> select now(); +-----------------------+ | now() | +-----------------------+ | 2019-06-02 10 :36 :49 | +-----------------------+ 1 row in set (0.00 sec)Insert some records in the table using ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
391 Views
Let us first create a table with one of the column as ID −mysql> create table DemoTable ( ID int, StudentName varchar(10), CountryName varchar(20) ); Query OK, 0 rows affected (0.70 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(0, 'David', 'AUS'); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable values(3, 'Chris', 'UK'); Query OK, 1 row affected (0.27 sec) mysql> insert into DemoTable values(8, 'Carol', 'US'); Query OK, 1 row affected (0.26 sec) mysql> insert into DemoTable values(9, 'Sam', 'US'); Query OK, 1 row affected (0.14 ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
128 Views
Use keyword AS for this. Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Name varchar(20) ); Query OK, 0 rows affected (3.16 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Name) values('John'); Query OK, 1 row affected (0.50 sec) mysql> insert into DemoTable(Name) values('Robert'); Query OK, 1 row affected (0.29 sec) mysql> insert into DemoTable(Name) values('David'); Query OK, 1 row affected (0.54 sec)Display all records from the table using select statement −mysql> select *from DemoTable;Output+----+--------+ | Id | Name | ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
204 Views
To order with a custom rule, use the ORDER BY FIELD(). Let us first create a table −mysql> create table DemoTable ( Number int ); Query OK, 0 rows affected (0.55 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(1); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(4); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable values(2); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(3); Query OK, 1 row affected (0.14 sec)Display all records from the table using select statement −mysql> ... Read More
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
3K+ Views
To combine multiple rows into a comma delimited list, use the GROUP_CONCAT() method. Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Name varchar(30), Marks int ); Query OK, 0 rows affected (0.52 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Name, Marks) values('John', 67); Query OK, 1 row affected (0.25 sec) mysql> insert into DemoTable(Name, Marks) values('Carol', 69); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable(Name, Marks) values('Sam', 69); Query OK, 1 row affected (0.12 sec) mysql> insert ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
115 Views
You can use the field() for this. Let us first create a table −mysql> create table DemoTable ( Value int ); Query OK, 0 rows affected (0.80 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(10); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values(70); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(60); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(56); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values(81); Query OK, 1 row affected (0.44 sec) mysql> ... Read More