AmitDiwan has Published 10740 Articles

Delete only specific rows in a table with MySQL

AmitDiwan

AmitDiwan

Updated on 24-Dec-2019 07:46:55

486 Views

To delete only specific rows, use MySQL NOT IN(). Let us first create a table −mysql> create table DemoTable1830      (      StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,      StudentName varchar(20)      )AUTO_INCREMENT=101; Query OK, 0 rows affected (0.00 sec)Insert some records in the table ... Read More

MySQL query to return the count of only NO values from corresponding column value

AmitDiwan

AmitDiwan

Updated on 24-Dec-2019 07:45:54

167 Views

Let us first create a table −mysql> create table DemoTable1829      (      Name varchar(20),      isTopper ENUM('YES', 'NO')      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1829 values('Chris', 'yes'); Query OK, 1 row ... Read More

Is it possible to add a set of elements in one cell with MySQL?

AmitDiwan

AmitDiwan

Updated on 24-Dec-2019 07:44:46

101 Views

To add a set of elements in a single cell, use the concept of JSON. Let us first create a table −mysql> create table DemoTable1828      (      EmployeeId int,      EmployeeRecords JSON      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the ... Read More

Perform mathematical operations in a MySQL Stored Procedure?

AmitDiwan

AmitDiwan

Updated on 24-Dec-2019 07:41:15

860 Views

Let us create a stored procedure. Here, we are calculating amount*quantity i.e. implementing mathematical operations −mysql> delimiter // mysql> create procedure calculation_proc(amount int, quantity int)      begin      select amount, quantity, (amount*quantity) as Total;      end      // Query OK, 0 rows affected (0.00 sec) mysql> ... Read More

How to search for ^ character in a MySQL table?

AmitDiwan

AmitDiwan

Updated on 24-Dec-2019 07:40:06

520 Views

To search for ^ character, use the LIKE operator as in the below syntax −select table_schema, table_name, column_name  from information_schema.columns  where column_name like '%^%';Let us first create a table −mysql> create table DemoTable1826      (      `^` varchar(20),      Name varchar(20),      `^Age` int     ... Read More

Display only NOT NULL values from a column with NULL and NOT NULL records in MySQL

AmitDiwan

AmitDiwan

Updated on 24-Dec-2019 07:38:49

558 Views

For this, you can use IS NOT NULL property. Let us first create a table −mysql> create table DemoTable1      (      DueDate date      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1 values('2019-09-10'); Query ... Read More

Implement If else in stored procedure in MySQL?

AmitDiwan

AmitDiwan

Updated on 24-Dec-2019 06:40:10

432 Views

To implement if-else, the syntax is as follows −if yourCondition then      yourStatement1;     else     yourStatement2;     end if ;To understand the above concept for if-else in a stored procedure, let us create a stored procedure −mysql> delimiter // mysql> create procedure If_else_stored_demo(value int)   ... Read More

How to increase precision with division in MySQL?

AmitDiwan

AmitDiwan

Updated on 24-Dec-2019 06:32:19

773 Views

To increase precision with division, use MySQL CAST(). Let us first create a table −mysql> create table DemoTable1823      (      Value int      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1823 values(1); Query OK, ... Read More

Update record on a specific date matching the current date in MySQL

AmitDiwan

AmitDiwan

Updated on 24-Dec-2019 06:30:57

756 Views

Let us first create a table −mysql> create table DemoTable1822      (      Amount int,      DueDate date      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1822 values(1000, '2019-10-11'); Query OK, 1 row affected ... Read More

Will MySQL work if we won’t include the size of VARCHAR while creating a new table?

AmitDiwan

AmitDiwan

Updated on 24-Dec-2019 06:29:40

145 Views

No, the query won’t work. Let’s create the same scenario and check the error −mysql> create table DemoTable1821      (      Id int,      FirstName varchar,      LastName varchar      ); ERROR 1064 (42000): You have an error in your SQL syntax; check the manual ... Read More

Advertisements