- 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
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
2K+ Views
The following is the code to create a database in MySQL from Java. We are creating the database with name, “Customer_Tracker_Database”import java.sql.Connection; import java.sql.DriverManager; import java.sql.Statement; public class CreateDatabaseDemo { public static void main(String[] args) { Connection con=null; Statement stmt=null; String yourDatabaseName="Customer_Tracker_Database"; try { con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test3?useSSL=false", "root", "123456"); stmt = con.createStatement(); int status = stmt.executeUpdate("CREATE DATABASE "+yourDatabaseName); if(status > 0) { System.out.println("Database ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
94 Views
For returned record set order, you need to use FIND_IN_SET() function. For an example, let us create a table.mysql> create table returnRecordSetOrderDemo -> ( -> Id int, -> Name varchar(20) -> ); Query OK, 0 rows affected (1.01 sec)Insert some records in the table using insert command.The query is as follows.mysql> insert into returnRecordSetOrderDemo values(100, 'John'); Query OK, 1 row affected (0.13 sec) mysql> insert into returnRecordSetOrderDemo values(130, 'Carol'); Query OK, 1 row affected (0.13 sec) mysql> insert into returnRecordSetOrderDemo values(103, 'Bob'); Query OK, 1 row affected (0.17 sec) mysql> insert into returnRecordSetOrderDemo values(134, 'Sam'); Query OK, ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
756 Views
Use any predefined function with select query or you can print some words with the select query in order to test connection with query.The syntax is as follows.SELECT yourValue;The select query with predefined function is as follows.The syntax is as follows.SELECT anyPredefinedFunctionName();Now you can implement the above syntax in order to test connection with query.Case 1 -The query is as follows.mysql> select "This is MySQL" as Display;The following is the output.+---------------+ | Display | +---------------+ | This is MySQL | +---------------+ 1 row in set (0.00 sec)Case 2 -The query is as follows.mysql> select ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
1K+ Views
You can use IN operator to select from one table that does not exist in another. To understand the above syntax, let us create a table.The first table name is A and second table name is B. The query to create a table is as followsmysql> create table A -> ( -> Value int -> ); Query OK, 0 rows affected (0.56 sec)Now you can insert some records in the table using insert command.The query is as followsmysql> insert into A values(10); Query OK, 1 row affected (0.23 sec) mysql> insert into A values(20); Query OK, 1 ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
869 Views
If the MySQL column contains dot (.) in its name, then you need to use backticks around the column name. To understand the above concept, let us create a table. The query to create a table is as followsmysql> create table UpdateDemo -> ( -> UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> `User.FirstName.LastName` varchar(60) -> ); Query OK, 0 rows affected (0.54 sec)Insert some records in the table using insert command.The query is as followsmysql> insert into UpdateDemo(`User.FirstName.LastName`) values('John Smith'); Query OK, 1 row affected (0.14 sec) mysql> insert into UpdateDemo(`User.FirstName.LastName`) values('Adam Smith'); Query OK, ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
3K+ Views
In order to get file extension of file as a result of SQL query, you can use SUBSTRING_INDEX().The syntax is as followsselect substring_index(yourColumnName, '.', -1) as anyAliasName from yourTableName;To understand the above syntax, let us create a table. The query to create a table is as followsmysql> create table getFileExtensionDemo -> ( -> File_Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> File_Name text -> ); Query OK, 0 rows affected (0.53 sec)Insert some records in the table using insert command.The query is as followsmysql> insert into getFileExtensionDemo(File_Name) values('John.AllMySQLConcept.doc'); Query OK, 1 row affected (0.17 sec) mysql> ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
10K+ Views
To set all values in a single column MySQL query, you can use UPDATE command.The syntax is as follows.update yourTableName set yourColumnName =yourValue;To understand the above syntax, let us create a table. The query to create a table is as follows.mysql> create table setAllValuesDemo -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> Name varchar(20), -> Amount int -> ); Query OK, 0 rows affected (0.64 sec)Now you can insert some records in the table using insert command.The query is as follows.mysql> insert into setAllValuesDemo(Name, Amount) values('John', 2345); Query OK, 1 row affected ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
3K+ Views
You can use LIKE operator to find strings with a given prefix.The syntax is as followsselect *from yourTableName where yourColumnName LIKE 'yourPrefixValue%';To understand the above syntax, let us create a table. The query to create a table is as followsmysql> create table findStringWithGivenPrefixDemo -> ( -> UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> UserMessage text -> ); Query OK, 0 rows affected (0.82 sec)Insert some records in the table using insert command.The query is as followsmysql> insert into findStringWithGivenPrefixDemo(UserMessage) values('Hi Good Morning !!!'); Query OK, 1 row affected (0.17 sec) mysql> insert into findStringWithGivenPrefixDemo(UserMessage) values('Hey ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
17K+ Views
Use IFNULL or COALESCE() function in order to convert MySQL NULL to 0.The syntax is as followsSELECT IFNULL(yourColumnName, 0) AS anyAliasName FROM yourTableName; The second syntax is as follows: SELECT COALESCE(yourColumnName, 0) AS anyAliasName FROM yourTableName;Let us first create a table. The query to create a table is as followsmysql> create table convertNullToZeroDemo -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> Name varchar(20), -> Salary int -> ); Query OK, 0 rows affected (1.28 sec)Insert some records in the table using insert command.The query is as followsmysql> insert into convertNullToZeroDemo(Name, Salary) values('John', ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
9K+ Views
You need to use ORDER BY clause to get the second last row of a table in MySQL.The syntax is as follows.select *from yourTableName order by yourColumnName DESC LIMIT 1, 1;To understand the above syntax, let us create a table. The query to create a table is as follows.mysql> create table secondLastDemo -> ( -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> StudentName varchar(10) -> ); Query OK, 0 rows affected (0.52 sec)Insert some records in the table using insert command.The query is as follows.mysql> insert into secondLastDemo(StudentName) values('Larry'); Query OK, 1 row affected (0.15 ... Read More