AmitDiwan has Published 8358 Articles

How to list all variables initialized by SET operator in MySQL?

AmitDiwan

AmitDiwan

Updated on 26-Dec-2019 07:22:55

322 Views

To list all variables initialized by SET operator, the syntax is as follows −select * from performance_schema.user_variables_by_thread;Here is the query to set the variable −mysql> set @FirstName='John'; Query OK, 0 rows affected (0.00 sec) mysql> set @LastName='Doe'; Query OK, 0 rows affected (0.00 sec)Here is the query to display the ... Read More

Increment date/time value by second with MySQL query?

AmitDiwan

AmitDiwan

Updated on 26-Dec-2019 07:21:06

589 Views

For this, use date_add() with interval command. Let us first create a table −mysql> create table DemoTable1867      (      ArrivalTime datetime      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1867 values('2019-10-12 12:34:45'); Query OK, ... Read More

MySQL query to get string from one column and find its position in another column with comma separated values?

AmitDiwan

AmitDiwan

Updated on 26-Dec-2019 07:19:48

322 Views

For this, use FIND_IN_SET(). Let us first create a table −mysql> create table DemoTable1866      (      Value1 int,      ListOfValues varchar(100)      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1866 values(56, '78, 56, ... Read More

How to assign the result of a MySQL query into a variable?

AmitDiwan

AmitDiwan

Updated on 26-Dec-2019 07:16:28

1K+ Views

Use @anyVariableName to assign the result of a query into a variable. Let us first create a table −mysql> create table DemoTable1864      (      Id int,      FirstName varchar(20),      LastName varchar(20)      ); Query OK, 0 rows affected (0.00 sec)Insert some records in ... Read More

How to set default value for empty row in MySQL?

AmitDiwan

AmitDiwan

Updated on 26-Dec-2019 06:54:31

765 Views

To set default value for empty row, use the concept of COALESCE(). Let us first create a table −mysql> create table DemoTable1863      (      FirstName varchar(20)      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into ... Read More

How to find records with a null value in a set of columns with MySQL

AmitDiwan

AmitDiwan

Updated on 26-Dec-2019 06:51:44

252 Views

For this, use the concept of GREATEST(). Let us first create a table −mysql> create table DemoTable1862      (      Value1 int,      Value2 int,      Value3 int,      Value4 int      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the ... Read More

How to find rows with exact value in one or more columns with MySQL?

AmitDiwan

AmitDiwan

Updated on 26-Dec-2019 06:48:18

490 Views

For this, you can use GROUP BY HAVING with subquery. Let us first create a table −mysql> create table DemoTable1861      (      Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,      Name varchar(20),      Marks int      ); Query OK, 0 rows affected (0.00 sec)Insert ... Read More

How to use an OUT parameter / read data with SELECT from table in a MySQL procedure?

AmitDiwan

AmitDiwan

Updated on 26-Dec-2019 06:46:30

593 Views

For this, you can use SELECT INTO. Let us first create a table −mysql> create table DemoTable1860      (      Amount int      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1860 values(1590); Query OK, 1 ... Read More

Is there an easy way to rename a table in a MySQL procedure?

AmitDiwan

AmitDiwan

Updated on 26-Dec-2019 06:44:11

248 Views

Yes, use the ALTER command with RENAME. Let us first create a table −mysql> create table DemoTable1859      (      Id int      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1859 values(101); Query OK, 1 ... Read More

Find duplicate column values in MySQL and display them

AmitDiwan

AmitDiwan

Updated on 26-Dec-2019 06:39:26

710 Views

For this, use GROUP BY HAVING clause. Let us first create a table −mysql> create table DemoTable1858      (      ModelNumber varchar(50)      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1858 values('Audi A4'); Query OK, ... Read More

Advertisements