- 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)
290 Views
Use ORDER BY to fix a record and then displayselect * from yourTableName order by yourColumnName1=yourValue desc, yourColumnName2;Let us first create a table −mysql> create table DemoTable1932 ( UserName varchar(20), ShippingDate date ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1932 values('Chris', '2018-10-12'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1932 values('David', '2019-04-11'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1932 values('Mike', '2016-12-04'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1932 values('Carol', '2017-12-26'); Query OK, 1 ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
599 Views
For month and year in a specific format, use DATE_FORMAT() along with STR_TO_DATE(). Let us first create a table −mysql> create table DemoTable1931 ( ShippingDate varchar(40) ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1931 values('10-11-2017'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1931 values('31-01-2019'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1931 values('02-02-2018'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1931 values('10-06-2013'); Query OK, 1 row affected (0.00 sec)Display all records from the table using select ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
441 Views
For this, you can use date_add(). Let us first create a table −mysql> create table DemoTable1930 ( DueTime datetime ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1930 values('2017-10-21'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1930 values('2019-12-14'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1930 values('2018-11-26'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1930 values('2014-06-16'); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> select * from DemoTable1930;This will ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
524 Views
To reset primary key, at first use TRUNCATE table, then use ALTER TABLE. Let us first create a table −mysql> create table DemoTable1929 ( UserId int NOT NULL AUTO_INCREMENT, PRIMARY KEY(UserId) ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1929 values(); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1929 values(); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1929 values(); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> select * from DemoTable1929;This ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
3K+ Views
To insert in a table in stored procedure, the syntax is as follows −create procedure yourProcedureName(OptionalParameter) begin insert into yourTableName() values(yourValue1, yourValue2, ...N); endTo understand the above syntax, let us first create a table −mysql> create table DemoTable1928 ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Name varchar(20), Age int ); Query OK, 0 rows affected (0.00 sec)Here is the query to create a stored procedure −mysql> delimiter // mysql> create procedure insert_demo(IN Name varchar(40), IN Age int) begin insert into DemoTable1928(Name, Age) values(Name, Age); end // Query OK, ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
367 Views
The coalesce() can be used to print first NOT NULL column value. Let us first create a table −mysql> create table DemoTable1927 ( StudentName varchar(20), StudentSubject varchar(20) ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1927 values('Chris', 'MySQL'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1927 values('David', NULL); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1927 values(NULL, 'MongoDB'); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> select * from DemoTable1927;This will ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
53 Views
For this, you can use ORDER BY CASE statement. Let us create a table −mysql> create table DemoTable1926 ( Position varchar(20), Number int ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1926 values('Highest', 50); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1926 values('Highest', 30); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1926 values('Lowest', 100); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1926 values('Lowest', 120); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1926 values('Lowest', ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
87 Views
For this, use UPDATE command along with CASE statement. Let us first create a table −mysql> create table DemoTable1925 ( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentName varchar(20), StudentMarks int ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1925(StudentName, StudentMarks) values('Chris', 98); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1925(StudentName, StudentMarks) values('David', 45); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> select * from DemoTable1925;This will produce the following output −+-----------+-------------+--------------+ | ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
85 Views
To update records with a specific year, use the YEAR() method as in the below syntax:update yourTableName set yourColumnName1=yourValue1 where YEAR(str_to_date(yourColumnName2, '%d/%m/%Y'))=yourValue2;Let us first create a table −mysql> create table DemoTable1924 ( UserName varchar(20), UserJoiningDate varchar(40) ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1924 values('Chris', '10/12/2010'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1924 values('David', '20/01/2011'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1924 values('Mike', '20/01/2010'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1924 values('Carol', ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
823 Views
Let us create a table −mysql> create table DemoTable1923 ( UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY, UserName varchar(20) ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1923(UserId, UserName) select 101 as UserId, 'Chris' as UserName; Query OK, 1 row affected (0.00 sec) Records: 1 Duplicates: 0 Warnings: 0 mysql> insert into DemoTable1923(UserId, UserName) select 102 as UserId, 'Robert' as UserName; Query OK, 1 row affected (0.00 sec) Records: 1 Duplicates: 0 Warnings: 0 mysql> insert into DemoTable1923(UserId, UserName) ... Read More