AmitDiwan has Published 10744 Articles

How to set default value for empty row in MySQL?

AmitDiwan

AmitDiwan

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

673 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

227 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

452 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

558 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

222 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

679 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

MySQL query to get all characters before a specific character hyphen

AmitDiwan

AmitDiwan

Updated on 26-Dec-2019 06:38:27

1K+ Views

For this, you can use SUBSTRING_INDEX(). Let us first create a table −mysql> create table DemoTable1857      (      Name varchar(20)      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1857 values('John-Smith'); Query OK, 1 row ... Read More

Using GROUP_CONCAT() on bit fields returns garbage in MySQL? How to fix?

AmitDiwan

AmitDiwan

Updated on 26-Dec-2019 06:37:09

171 Views

To fix, use group_concat() with addition of 0 with column. Let us first create a table −mysql> create table DemoTable1856      (      Id int,      Value bit(1)      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> ... Read More

Which MySQL Datatype should be used for storing BloodType?

AmitDiwan

AmitDiwan

Updated on 26-Dec-2019 06:35:52

989 Views

To store BloodType, use varchar(3) or ENUM. Let us first create a table −mysql> create table DemoTable1855      (      BloodType varchar(3)      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1855 values('A+'); Query OK, 1 ... Read More

Distinct number of specific items in list with MySQL

AmitDiwan

AmitDiwan

Updated on 26-Dec-2019 06:34:03

194 Views

To find distinct number of specific items, use COUNT() along with GROUP BY clause. Let us first create a table −mysql> create table DemoTable1854      (      Name varchar(20)      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> ... Read More

Advertisements