
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

12K+ Views
To add the JDBC MySQL driver to an Eclipse project, you need to follow the below steps.The first step is as follows:Step1: Create a dynamic web project with some name in Eclipse.Step2: After pressing the Dynamic Web Project, a new window will open. Now give the project name. The screenshot is as follows:After clicking the Finish button, you will get a project structure. The screenshot is as follows:Therefore, I have a project name JDBCJarFiles and in WEB-INF, there is a lib folder. You can add JDBC jar files in lib folder. Now, paste the jar files here. The screenshot is as ... Read More

2K+ Views
You need to use COALESCE() function for this. The syntax is as follows:INSERT INTO yourTableName(yourColumnName1, yourColumnName2) SELECT 1 + COALESCE((SELECT MAX(yourColumnName1) FROM yourTableName WHERE yourColumnName2=’yourValue’), 0), ’yourValue’;To understand the above syntax, let us create a table. The query to create a table is as follows:mysql> create table InsertMaxPlus1Demo -> ( -> Id int, -> Name varchar(20) -> ); Query OK, 0 rows affected (1.27 sec)Now you can insert some records in the table using insert command. The query is as follows:mysql> insert into InsertMaxPlus1Demo(Id, Name) values(1, 'John'); Query OK, 1 row affected (0.12 sec) mysql> insert ... Read More

5K+ Views
If you want case-insensitive distinct, you need to use UPPER() or LOWER().Case 1: Using UPPER().The syntax is as follows:SELECT DISTINCT UPPER(yourColumnName) FROM yourTableName;Case 2: Using LOWER().The syntax is as follows:SELECT DISTINCT LOWER(yourColumnName) FROM yourTableName;To understand the above syntax, let us create a table. The query to create a table is as follows:mysql> create table CaseInsensitiveDistinctDemo -> ( -> Id int NOT NULL AUTO_INCREMENT, -> UserEmailId varchar(30), -> UserPassword varchar(10), -> PRIMARY KEY(Id) -> ); Query OK, 0 rows affected (0.64 sec)Now you ... Read More

7K+ Views
To run SQL file in database, you need to use below syntax:mysql -u yourUserName -p yourDatabaseName < yourFileName.sqlTo understand the above syntax, let us open command prompt using windows+R shortcut key.The snapshot is as follows:After pressing OK button, you will get a command prompt. The snapshot is as follows:Now reach the bin directory, the snapshot is as follows:Here is my file ‘mydb.sql’ which is located in bin directory. The snapshot and content of SQL file is as follows:Now you can type the above syntax which I have discussed to run SQL file. The snapshot of command is as follows:Now you ... Read More

279 Views
You need to use subquery with select statement, one select for inner and one for outer. The inner select will return rows and outer will order by ascending order. The syntax is as follows:SELECT *FROM ( SELECT *FROM yourTableName ORDER BY yourColumnName1 DESC LIMIT 9 ) AS anyAliasName ORDER BY yourColumnName2;To understand the above syntax, let us create a table. The query to create a table is as follows:mysql> create table OrderByAfterLimit -> ( -> Id int NOT NULL AUTO_INCREMENT, -> UserName varchar(20), -> UserAge int, -> PRIMARY KEY(Id) -> ); Query OK, ... Read More

542 Views
To populate a table from query results, use the following syntax:INSERT yourTableName(yourColumnName1, yourColumnName2, yourColumnName3, ..........N) SELECT yourColumnName1, yourColumnName2, yourColumnName3, ..........N FROM yourAnotherTableName;To understand the above syntax, let us create a table. The first table is as follows with some records. The query to create a table is as follows:mysql> create table PopulateTableDemo -> ( -> Id int NOT NULL AUTO_INCREMENT, -> Name varchar(20), -> Amount int, -> ArrivalDateTime datetime, -> PRIMARY KEY(Id) -> ); Query OK, 0 rows affected (0.68 sec)Now you can insert some records in the table using insert command. The ... Read More

18K+ Views
If you want to login as a different user on MySQL, you need to use “mysql -u -p command”. The syntax is as follows to login as a different user.>mysql -u yourUsername -p After pressing enter key Enter password −To understand the above syntax, let us create a user in MySQL. The syntax is as follows −CREATE USER 'yourUserName'@'localhost' IDENTIFIED BY 'yourPassword';Now I am going to create a user with name ‘John’ and password is ‘john123456’. The query is as follows −mysql> CREATE USER 'John'@'localhost' IDENTIFIED BY 'john123456'; Query OK, 0 rows affected (0.15 sec)Now check the user has been ... Read More

9K+ Views
To delete last record (on condition) from a table, you need to use ORDER BY DESC with LIMIT 1. The syntax is as follows:DELETE FROM yourTableName WHERE yourColumnName1=yourValue ORDER BY yourColumnName2 DESC LIMIT 1;The above syntax will delete last record (on condition) from a table. It sorts the column in descending order and choose the first element to delete.To understand the above syntax, let us create a table. The query to create a table is as follows:mysql> create table UserLoginTable -> ( -> Id int NOT NULL AUTO_INCREMENT, -> UserId int, -> UserLoginDateTime datetime, -> PRIMARY ... Read More

972 Views
You need to use regular expression with ORDER BY clause. The syntax is as follows:SELECT *FROM yourTableName ORDER BY IF(yourColumnName RLIKE '^[a-z]', 1, 2), yourColumnName;To understand the above syntax, let us create a table. The query to create a table is as follows:mysql> create table AlphabetFirstThenNumberDemo -> ( -> Id int NOT NULL AUTO_INCREMENT, -> Name varchar(20), -> PRIMARY KEY(Id) -> ); Query OK, 0 rows affected (0.95 sec)Insert some records in the table using insert command. The query is as follows:mysql> insert into AlphabetFirstThenNumberDemo(Name) values('John'); Query OK, 1 row affected (0.37 sec) mysql> insert ... Read More

1K+ Views
To select multiple sum columns with MySQL query and display them in separate columns, you need to use CASE statement. The syntax is as follows:SELECT SUM( CASE WHEN yourColumnName1=’yourValue1’ THEN yourColumnName2 END ) AS yourSeparateColumnName1, SUM( CASE WHEN yourColumnName1=’yourValue2’ THEN yourColumnName2 END ) AS yourSeparateColumnName2, SUM( CASE WHEN yourColumnName1=’yourValue3’ THEN yourColumnName2 END ) AS yourSeparateColumnName3, . . . N FROM yourTableName;To understand the above syntax, let us create a table. The query to create a table is as follows:mysql> create table selectMultipleSumDemo -> ( -> Id int NOT NULL AUTO_INCREMENT, -> PlayerName varchar(20), -> PlayerScore int, ... Read More