
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Found 4381 Articles for MySQL

2K+ Views
Let us first create a table −mysql> create table DemoTable -> ( -> Date1 date, -> Date2 date -> ); Query OK, 0 rows affected (1.04 sec)Insert some records in the table using insert command &miuns;mysql> insert into DemoTable values('2017-01-10', '2017-12-10'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('2018-12-31', '2015-01-02'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('2020-03-01', '2019-06-15'); Query OK, 1 row affected (0.19 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+------------+------------+ | Date1 ... Read More

3K+ Views
For the current date, use CURDATE(). Also, use STR_TO_DATE() to format date and compare it with the current date as in the below syntax −Syntaxselect *from yourTableName where str_to_date(yourColumnName, 'yourFormatSpecifier')=curdate();Let’s say the current date is 27/10/2019.Let us first create a table −mysql> create table DemoTable -> ( -> JoiningDate varchar(40) -> ); Query OK, 0 rows affected (0.79 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('27/10/2017'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('27/10/2018'); Query OK, 1 row affected (0.78 sec) mysql> insert into DemoTable values('27/10/2019'); Query ... Read More

627 Views
For this, you can use ORDER BY FIELD. Let us first create a table −mysql> create table DemoTable -> ( -> Id int, -> Name varchar(20) -> ); Query OK, 0 rows affected (1.78 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(101, 'Chris'); Query OK, 1 row affected (0.38 sec) mysql> insert into DemoTable values(201, 'Mike'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(110, 'Adam'); Query OK, 1 row affected (0.52 sec) mysql> insert into DemoTable values(250, 'John'); Query OK, 1 row affected (0.33 sec)Display all ... Read More

539 Views
For this, use UNION more than once in a single MySQL query. Let us first create a table −mysql> create table DemoTable -> ( -> Value1 int, -> Value2 int, -> Value3 int -> ); Query OK, 0 rows affected (0.69 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(20, null, null); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values(20, null, null); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values(20, null, null); Query OK, 1 row affected (0.12 sec) mysql> insert into ... Read More

214 Views
CASE statement with the WHEN clause is used to work around conditions. Following is the syntax−select *, case when yourCondition then yourStatement when yourCondition then yourStatement . . else yourStatement from yourTableName;Let us first create a table −mysql> create table DemoTable -> ( -> StudentName varchar(20), -> StudentMarks int -> ); Query OK, 0 rows affected (0.77 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Chris', 78); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values('Robert', 88); Query OK, 1 row affected (0.14 sec) ... Read More

106 Views
To replace duplicate records and avoid any error while inserting, use INSERT ON DUPLICATE KEY UPDATE. Let us first create a table −mysql> create table DemoTable -> ( -> Id int, -> Name varchar(20), -> UNIQUE(Id, Name) -> ); Query OK, 0 rows affected (0.78 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(101, 'Chris') on duplicate key update Id=10001, Name='Robert'; Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable values(102, 'Mike') on duplicate key update Id=10001, Name='Robert'; Query OK, 1 row affected (0.17 sec) mysql> insert into ... Read More

3K+ Views
Yes, we can turn a column records into a list using the MySQL GROUP_CONCAT(). Let us first create a table −mysql> create table DemoTable -> ( -> ClientId int, -> ClientName varchar(20) -> ); Query OK, 0 rows affected (0.88 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(100, 'Chris'); Query OK, 1 row affected (0.54 sec) mysql> insert into DemoTable values(100, 'Robert'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(100, 'Adam'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(100, 'David'); Query OK, ... Read More

704 Views
To create a temporary table with dates, use the CREATE TEMPORARY TABLE in MySQL. Following is the syntax −Syntaxcreate temporary table yourTableName( yourColumnName datetime );Let us first create a table −mysql> create temporary table DemoTable -> ( -> DueDate datetime -> ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(now()); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable values(curdate()); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable values('2018-01-21'); Query OK, 1 row affected (0.00 sec) mysql> insert into ... Read More

856 Views
To increase item value for multiple items in a single query, you can use the CASE statement in MySQL. Let us first create a table −mysql> create table DemoTable -> ( -> ProductName varchar(20), -> ProductPrice int -> ); Query OK, 0 rows affected (0.51 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Product-1', 700); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('Product-2', 1000); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('Product-3', 3000); Query OK, 1 row affected (0.10 sec)Display all records from ... Read More

2K+ Views
For this, you can use GROUP BY HAVING along with the COUNT(*) function. Let us first create a table −mysql> create table DemoTable -> ( -> Value int -> ); Query OK, 0 rows affected (0.47 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(20); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values(10); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable values(30); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values(10); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable ... Read More