- 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)
260 Views
To get the left substring, use LEFT() along with substring_index(). For example, let’s say the file path is −“/MyFile/JavaProgram/Hello.java “Here, we will see how to display the entire file path except for the file name i.e. −/MyFile/JavaProgram/Let us first create a table −mysql> create table DemoTable ( FileLocation text ); Query OK, 0 rows affected (0.57 secInsert some records in the table using insert command −mysql> insert into DemoTable values('/MyFile/JavaProgram/Hello.java'); Query OK, 1 row affected (0.27 sec) mysql> insert into DemoTable values('/C/AllPrograms/animation.gif'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('/E/FavFile/ChatProgram.java'); Query OK, 1 row affected ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
222 Views
To get the fourth-highest value, use LIMIT OFFSET along with ORDER BY. Let us first create a table −mysql> create table DemoTable ( Amount int ); Query OK, 0 rows affected (0.88 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(980); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(670); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values(890); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(995); Query OK, 1 row affected (0.25 sec) mysql> insert into DemoTable values(198); Query OK, 1 row affected ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
354 Views
Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, FirstName varchar(100), LastName varchar(100) ); Query OK, 0 rows affected (1.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(FirstName, LastName) values('David', 'Miller'); Query OK, 1 row affected (0.35 sec) mysql> insert into DemoTable(FirstName, LastName) values('Carol', 'Miller'); Query OK, 1 row affected (0.37 sec) mysql> insert into DemoTable(FirstName, LastName) values('John', 'Doe'); Query OK, 1 row affected (0.21 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
3K+ Views
To suppress warnings, set SQL_NOTES=0. Let us see an example.At first, we will set SQL_NOTES to 1 −mysql> SET sql_notes = 1; Query OK, 0 rows affected (0.00 sec)Now, let us drop a table which does not exist. As you can see a warning message is now visible −mysql> drop table if exists web.DemoTable; Query OK, 0 rows affected, 1 warning (0.07 sec)To look at the above warning message, you need to just use the SHOW WARNINGS command −mysql> show warnings;This will produce the following output displaying the warning message −+-------+------+-----------------------------------+ | Level | Code | Message ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
131 Views
For custom order, use ORDER BY FIELD(). Let us first create a table −mysql> create table DemoTable ( Title varchar(100) ); Query OK, 0 rows affected (0.62 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Java_1+'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('MySQL_23+'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('MongoDB++'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('C++_23'); Query OK, 1 row affected (0.13 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
79 Views
Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Name varchar(100), Score int ); Query OK, 0 rows affected (1.10 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Name, Score) values('John', 45); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(Name, Score) values('Chris', null); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(Name, Score) values('David', null); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable(Name, Score) values('Bob', 1); Query OK, 1 row affected (0.11 sec)Display all records from ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
557 Views
For this, you can use the INTERVAL 7 day concept. Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, AdmissionDate datetime ); Query OK, 0 rows affected (0.83 sec)Note − Let’s say the current date is 2019-08-23.Insert some records in the table using insert command −mysql> insert into DemoTable(AdmissionDate) values('2019-01-23'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable(AdmissionDate) values('2019-08-15'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable(AdmissionDate) values('2019-08-16'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable(AdmissionDate) values('2019-08-24'); Query OK, 1 ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
91 Views
Let us first create a table −mysql> create table DemoTable ( value1 int, value2 int, value3 int ); Query OK, 0 rows affected (0.70 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(20, 40, null); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable values(40, 40, null); Query OK, 1 row affected (0.26 sec) mysql> insert into DemoTable values(null, null, null); Query OK, 1 row affected (0.17 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+--------+--------+--------+ | value1 | value2 ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
98 Views
For this, use ORDER BY with a modulus operator. Let us first create a table −mysql> create table DemoTable ( StudentId int, StudentName varchar(100) ); Query OK, 0 rows affected (1.88 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(100, 'Chris'); Query OK, 1 row affected (0.41 sec) mysql> insert into DemoTable values(101, 'Robert'); Query OK, 1 row affected (0.30 sec) mysql> insert into DemoTable values(102, 'David'); Query OK, 1 row affected (0.94 sec) mysql> insert into DemoTable values(103, 'Mike'); Query OK, 1 row affected (0.23 sec)Display all records from the table using ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
298 Views
You can use an aggregate function SUM() along with IF(). Let us first create a table −mysql> create table DemoTable ( FirstName varchar(100), LastName varchar(100) ); Query OK, 0 rows affected (2.80 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Adam', 'Smith'); Query OK, 1 row affected (0.25 sec) mysql> insert into DemoTable values('John', 'Smith'); Query OK, 1 row affected (0.36 sec) mysql> insert into DemoTable values('John', 'Doe'); Query OK, 1 row affected (1.38 sec) mysql> insert into DemoTable values('Bob', 'Doe'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values('Sam', ... Read More