AmitDiwan has Published 10744 Articles

MySQL query to update a specific cell to be empty

AmitDiwan

AmitDiwan

Updated on 01-Oct-2019 07:01:19

442 Views

Let us first create a table −mysql> create table DemoTable (    Id int,    Name varchar(50) ); Query OK, 0 rows affected (0.47 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(1001, 'Robert'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable ... Read More

MySQL query to sum 3 different values in a column displaying total of each value in result set?

AmitDiwan

AmitDiwan

Updated on 01-Oct-2019 06:59:33

205 Views

For this, you can use a CASE statement. Let us first create a table −mysql> create table DemoTable (    ProductName varchar(100),    ProductRating ENUM('1', '2', '3') ); Query OK, 0 rows affected (0.50 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Product-1', 3); Query ... Read More

Inserting multiple parameter values into a single column with MySQL?

AmitDiwan

AmitDiwan

Updated on 01-Oct-2019 06:56:35

459 Views

To insert multiple parameter values into a single column, use the CONCAT_WS() or CONCAT(). Let us first create a table −mysql> create table DemoTable (    Name varchar(100),    Age int,    CountryName varchar(100),    PersonInformation text ); Query OK, 0 rows affected (0.67 sec)Following is the query to insert ... Read More

Select into a user-defined variable with MySQL

AmitDiwan

AmitDiwan

Updated on 01-Oct-2019 06:54:37

439 Views

For user-defined variables, we use @ in MySQL. Following is the syntax. Here, @anyVariableName is our user-defined variable −select yourColumnName into @anyVariableName from yourTableName where yourCondition;Let us first create a table −mysql> create table DemoTable (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Name varchar(100) ); Query OK, ... Read More

MySQL query to get the length of all columns and display the result in a single new column?

AmitDiwan

AmitDiwan

Updated on 01-Oct-2019 06:52:59

641 Views

To get the length of all columns i.e. the count of all the characters for column values, use char_length(). Let us first create a table. Here, we have two columns, therefore we will calculate for each row consisting of both the values FirstName and LastName −mysql> create table DemoTable ( ... Read More

MySQL query to delete a DATE older than 30 days from another date?

AmitDiwan

AmitDiwan

Updated on 01-Oct-2019 06:51:08

692 Views

Following is the syntax −delete from yourTableName where yourColumnName < (yourAnotherDateValue - INTERVAL 30 DAY);Let us first create a table −mysql> create table DemoTable (    DueDate date ); Query OK, 0 rows affected (0.68 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2019-08-25'); Query ... Read More

MySQL query to display columns name first name, last name as full name in a single column?

AmitDiwan

AmitDiwan

Updated on 01-Oct-2019 06:49:29

13K+ Views

For this, use CONCAT() method in MySQL. Let us first create a table −mysql> create table DemoTable (    FirstName varchar(50),    LastName varchar(50) ); Query OK, 0 rows affected (0.63 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Chris', 'Brown'); Query OK, 1 row ... Read More

How to alter column type of multiple columns in a single MySQL query?

AmitDiwan

AmitDiwan

Updated on 01-Oct-2019 06:47:21

842 Views

To alter column type of multiple columns in a single MySQL query, the syntax is as follows −alter table yourTableName modify column yourColumnName 1 yourDataType1, modify column yourColumnName 2 yourDataType2, . . N;Let us first create a table −mysql> create table DemoTable (    Id varchar(100),    FirstName text,   ... Read More

Get the count of two table fields in a single MySQL query?

AmitDiwan

AmitDiwan

Updated on 30-Sep-2019 08:28:18

686 Views

For this, you can use the CASE statement along with SUM(). Here, we will be finding the count of Male and Female records from a column with employee gender values. Let us first create a table −mysql> create table DemoTable (    EmployeeGender ENUM('Male', 'Female') ); Query OK, 0 rows ... Read More

What is the usage of “@” symbol in MySQL stored procedure?

AmitDiwan

AmitDiwan

Updated on 30-Sep-2019 08:26:39

1K+ Views

The @ symbol in a stored procedure can be used for user-defined session variables. Let us first create a table −mysql> create table DemoTable (    StudentName varchar(50) ); Query OK, 0 rows affected (1.30 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('John Smith'); ... Read More

Advertisements