- 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
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
307 Views
Let us first create a table −mysql> create table DemoTable1811 ( FirstName varchar(20), LastName varchar(20) ); Query OK, 0 rows affected (0.00 sec)Here is the query to add indexmysql> alter table DemoTable1811 ADD UNIQUE unique_index_first_last_name(FirstName, LastName); Query OK, 0 rows affected (0.00 sec) Records: 0 Duplicates: 0 Warnings: 0Insert some records in the table using insert command −mysql> insert into DemoTable1811 values('John', 'Smith'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1811 values('John', 'Doe'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1811 values('Adam', 'Smith'); Query OK, 1 ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
474 Views
Use the backticks symbol to consider ‘from’ as column name since it is a reserved word. We will now create a table with from reserved word surrounded by backtick −mysql> create table DemoTable1810 ( `from` varchar(20) ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1810 values('US'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1810 values('UK'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1810 values('AUS'); Query OK, 1 row affected (0.00 sec)Display all records from the table using ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
672 Views
To fetch a specific column value, use LIKE clause. Let us first create a table −mysql> create table DemoTable1809 ( Name varchar(20) ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1809 values('John'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1809 values('David'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1809 values('Mike'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1809 values('Johnson'); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
218 Views
For this, you can use STR_TO_DATE(), since we have date records in the following format: 21/11/2019.Let us first create a table −mysql> create table DemoTable1808 ( AdmissionDate varchar(20) ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1808 values('21/11/2019'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1808 values('01/01/2018'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1808 values('26/09/2017'); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> select * from DemoTable1808;This will ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
1K+ Views
For this, use GROUP_CONCAT() and CONCAT(). Let us first create a table −mysql> create table DemoTable1807 ( Id int ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1807 values(101); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1807 values(102); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1807 values(103); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> select * from DemoTable1807;This will produce the following output −+------+ | Id | ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
691 Views
To get data greater than equal to 1 day from the current date, use the concept of INTERVAL in MySQL.The current date is as follows −mysql> select curdate(); +------------+ | curdate() | +------------+ | 2019-11-29 | +------------+ 1 row in set (0.00 sec)We will first create a table −mysql> create table DemoTable1806 ( DueDate datetime ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1806 values('2019-11-28'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1806 values('2019-11-29'); Query OK, 1 row affected (0.00 ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
114 Views
For this, you can use COALESCE(). Let us first create a table −mysql> create table DemoTable1805 ( Name1 varchar(20), Name2 varchar(20) ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1805 values('Chris', NULL); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1805 values('David', 'Mike'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1805 values(NULL, 'Mike'); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> select * from DemoTable1805;This will produce the ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
83 Views
For this, you can use GROUP BY clause. To find maximum value, use MAX() function. Let us first create a table −mysql> create table DemoTable1804 ( Id int, Marks1 int, Marks2 int, Marks3 int ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1804 values(1, 56, 89, 34); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1804 values(1, 98, null, 94); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1804 values(2, 34, 45, 78); ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
167 Views
For this, you can use CONCAT() with CURDATE().There is no function with the name CONTAINS() in MySQL.Let us first get the current date. The current date is as follows −mysql> select curdate();This will produce the following output −+------------+ | curdate() | +------------+ | 2019-11-28 | +------------+ 1 row in set (0.00 sec)We will now create a table −mysql> create table DemoTable1803 ( Name varchar(20), JoiningYear varchar(20) ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1803 values('Chris', '2020/2017'); Query OK, 1 row ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
93 Views
For this, you can use DISTINCT keyword. Let us first create a table −mysql> create table DemoTable1801 ( Name varchar(20), Score int ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1801 values('John', 98); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1801 values('John', 98); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1801 values('John', 99); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1801 values('Carol', 99); Query OK, 1 row affected (0.00 sec)Display all records ... Read More