Kumar Varma has Published 110 Articles

MySQL query to get the character length for all the values in a column?

Kumar Varma

Kumar Varma

Updated on 30-Jun-2020 12:58:56

146 Views

To get the character length, use the CHAR_LENGTH() method. Let us first create a table −mysql> create table DemoTable    -> (    -> Name varchar(100)    -> ); Query OK, 0 rows affected (1.04 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('John'); Query ... Read More

Create a temporary table in a MySQL procedure?

Kumar Varma

Kumar Varma

Updated on 30-Jun-2020 12:56:38

2K+ Views

To create a temporary table in a MySQL procedure, following is the syntax −CREATE PROCEDURE yourProcedureName()    BEGIN       CREATE TEMPORARY TABLE yourTemporaryTableName SELECT yourValue;    ENDLet us implement the above syntax to create a temporary table and insert some records in the table. Following is the query ... Read More

MySQL query to display structure of a table

Kumar Varma

Kumar Varma

Updated on 30-Jun-2020 12:50:19

1K+ Views

To display structure of a table, following is the syntax −show create table yourTableName;Let us first create a table −mysql> create table DemoTable    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> EmployeeFirstName varchar(100),    -> EmployeeLastName varchar(100),    -> EmployeeAge int,    -> isMarried ... Read More

Multiple column sorting in MySQL?

Kumar Varma

Kumar Varma

Updated on 30-Jun-2020 12:48:49

82 Views

Let us first create a table −mysql> create table DemoTable    -> (    -> Id int,    -> Value int    -> ); Query OK, 0 rows affected (0.68 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(100, 85885); Query OK, 1 row affected ... Read More

Subquery to exclude a particular row in MySQL

Kumar Varma

Kumar Varma

Updated on 30-Jun-2020 12:42:49

272 Views

Let us first create a table −mysql> create table DemoTable    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> Name varchar(100),    -> Age int    -> ); Query OK, 0 rows affected (0.87 sec)Insert some records in the table using insert command −mysql> insert ... Read More

Get part of a string based on a character in MySQL?

Kumar Varma

Kumar Varma

Updated on 30-Jun-2020 12:39:04

88 Views

Let us first create a table −mysql> create table DemoTable    -> (    -> Code varchar(100)    -> ); Query OK, 0 rows affected (1.07 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('/101/102/106'); Query OK, 1 row affected (0.14 sec) mysql> insert ... Read More

Is there a way to retrieve the minimum value of fields in MySQL?

Kumar Varma

Kumar Varma

Updated on 30-Jun-2020 12:32:19

53 Views

Yes, you can use LEAST() function from MySQL −select least(yourColumnName1, yourColumnName2, ...N) from yourTableName;Let us first create a table −mysql> create table DemoTable    -> (    -> Date1 date,    -> Date2 date,    -> Date3 date    -> ); Query OK, 0 rows affected (0.54 sec)Insert some records ... Read More

How to add subtotal to a table column displaying NULL in MySQL?

Kumar Varma

Kumar Varma

Updated on 30-Jun-2020 12:28:25

168 Views

Let us first create a table −mysql> create table DemoTable -> ( -> Amount int, -> SubTotal int -> ); Query OK, 0 rows affected (0.65 sec)Insert some records in the table using insert command −ysql> insert into DemoTable(Amount) values(50); Query OK, 1 row affected (0.17 sec) mysql> insert ... Read More

Can we use “IF NOT IN” in a MySQL procedure?

Kumar Varma

Kumar Varma

Updated on 30-Jun-2020 12:15:04

85 Views

Let us first see the syntax of IF NOT IN in MySQL −if(yourVariableName  NOT IN (yourValue1, yourValue2, ........N) ) then    statement1 else    statement2 endif    Let us implement the above syntax to use IF NOT IN −mysql> DELIMITER // mysql> CREATE PROCEDURE IF_NOT_INDemo(IN value int)    ->   ... Read More

How to perform update in MySQL to disallow incrementing all the values above a specific value?

Kumar Varma

Kumar Varma

Updated on 30-Jun-2020 11:09:06

46 Views

Let us first create a table −mysql> create table DemoTable    -> (    -> Value int    -> ); Query OK, 0 rows affected (0.54 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(100); Query OK, 1 row affected (0.21 sec) mysql> insert ... Read More

Advertisements