Found 4378 Articles for MySQL

Delete rows with duplicate and similar content & get row with maximum number with MySQL select statement?

AmitDiwan
Updated on 10-Dec-2019 07:29:09

57 Views

Let us first create a table −mysql> create table DemoTable1468    -> (    -> Id int,    -> Name varchar(20),    -> Age int    -> ); Query OK, 0 rows affected (1.21 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1468 values(100, 'Chris', 23); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable1468 values(101, 'Bob', 25); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1468 values(102, 'David', 30); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1468 values(100, 'Chris', 23); Query OK, 1 row affected (0.35 sec) mysql> ... Read More

Get rows that have common value from the same table with different id in MySQL

AmitDiwan
Updated on 10-Dec-2019 07:13:42

764 Views

For this, you can use GROUP BY HAVING clause. Let us first create a table −mysql> create table DemoTable1467    -> (    -> Id int,    -> Name varchar(20)    -> ); Query OK, 0 rows affected (0.64 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1467 values(100, 'Chris'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable1467 values(110, 'David'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable1467 values(120, 'Mike'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable1467 values(100, 'Chris'); Query OK, 1 row affected (0.12 sec) ... Read More

Fastest way to insert with multiple values in a single MySQL query?

AmitDiwan
Updated on 10-Dec-2019 07:10:40

507 Views

Do not use the below query for this −insert into yourTableName values(yourValue1, yourValue2, ...N); insert into yourTableName values(yourValue1, yourValue2, ...N); insert into yourTableName values(yourValue1, yourValue2, ...N); . . . NYou can use below query as the fastest way to insert with multiple values in a single query −insert into yourTableName values(yourValue1, yourValue2, ...N), (yourValue1, yourValue2, ...N), (yourValue1, yourValue2, ...N), ...................N;Let us first create a table −mysql> create table DemoTable1466 -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> Name varchar(20),    -> Age int    -> ); Query OK, 0 rows affected (0.98 sec)Insert some records ... Read More

How to split string in MySQL using SUBSTRING_INDEX?

AmitDiwan
Updated on 10-Dec-2019 07:07:50

166 Views

Let us first create a table −mysql> create table DemoTable1465    -> (    -> Name varchar(40)    -> ); Query OK, 0 rows affected (0.54 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1465 values('Chris Brown'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable1465 values('David Miller'); Query OK, 1 row affected (0.26 sec) mysql> insert into DemoTable1465 values('John Doe'); Query OK, 1 row affected (0.14 sec)Display all records from the table using select statement −mysql> select * from DemoTable1465;This will produce the following output −+--------------+ | Name         | ... Read More

Implement DELETE query in MySQL stored procedure

AmitDiwan
Updated on 10-Dec-2019 07:06:10

2K+ Views

You can use stored procedure and can pass the value via parameter. Let us first create a table −mysql> create table DemoTable1464    -> (    -> Id int,    -> FirstName varchar(20)    -> ); Query OK, 0 rows affected (0.51 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1464 values(101, 'Chris Brown'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1464 values(102, 'John Doe'); Query OK, 1 row affected (0.09 sec)Display all records from the table using select statement −mysql> select * from DemoTable1464;This will produce the following output −+------+-------------+ | Id ... Read More

Concatenate multiple rows and columns in a single row with MySQL

AmitDiwan
Updated on 10-Dec-2019 07:02:27

1K+ Views

To concatenate multiple rows and columns in single row, you can use GROUP_CONCAT() along with CONCAT(). Let us first create a table −mysql> create table DemoTable1463    -> (    -> ClientId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> ClientName varchar(20),    -> ClientAge int    -> ); Query OK, 0 rows affected (1.37 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1463(ClientName, ClientAge) values('Adam Smith', 34); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1463(ClientName, ClientAge) values('John Doe', 29); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable1463(ClientName, ClientAge) values('David ... Read More

Perform mathematical calculations in a MySQL table with NULL and NON-NULL values

AmitDiwan
Updated on 10-Dec-2019 07:00:25

175 Views

For this, you can use IFNULL() and perform mathematical calculations with NULL and NON-NULL values. Let us first create a table −mysql> create table DemoTable1462    -> (    -> Value1 int,    -> Value2 int    -> ); Query OK, 0 rows affected (0.55 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1462 values(10, 20); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1462 values(50, NULL); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable1462 values(NULL, 70); Query OK, 1 row affected (0.25 sec)Display all records from the table using select ... Read More

MySQL ORDER BY 'ENUM' type value based on conditions

AmitDiwan
Updated on 10-Dec-2019 06:56:49

403 Views

For this, use ORDER BY CASE statement. Let us first create a table, wherein we have ENUM type column −mysql> create table DemoTable1461    -> (    -> DeckOfCards ENUM('K', 'J', 'A', 'Q')    -> ); Query OK, 0 rows affected (0.64 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1461 values('K'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1461 values('A'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable1461 values('J'); Query OK, 1 row affected (0.44 sec) mysql> insert into DemoTable1461 values('Q'); Query OK, 1 row affected (0.13 sec)Display all ... Read More

Fetch the size of a specific column values in MySQL and display the sum

AmitDiwan
Updated on 10-Dec-2019 06:48:53

84 Views

Let us first create a table −mysql> create table DemoTable1612    -> (    -> FirstName varchar(20),    -> LastName varchar(20)    -> ); Query OK, 0 rows affected (0.87 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1612 values('David', 'Brown'); Query OK, 1 row affected (0.75 sec) mysql> insert into DemoTable1612 values('John', 'Smith'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable1612 values('Bob', 'Taylor'); Query OK, 1 row affected (0.13 sec)Display all records from the table using select statement −mysql> select * from DemoTable1612;This will produce the following output −+-----------+----------+ | FirstName | ... Read More

Perform case insensitive SELECT using MySQL IN()?

AmitDiwan
Updated on 10-Dec-2019 06:43:45

177 Views

Let us first create a table −mysql> create table DemoTable1460    -> (    -> Name varchar(20)    -> ); Query OK, 0 rows affected (0.91 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1460 values('Chris'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable1460 values('David'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable1460 values('Bob'); Query OK, 1 row affected (0.52 sec) mysql> insert into DemoTable1460 values('Robert'); Query OK, 1 row affected (0.11 sec)Display all records from the table using select statement −mysql> select * from DemoTable1460;This will produce the following ... Read More

Advertisements