AmitDiwan has Published 10740 Articles

MySQL query to display custom text for empty columns

AmitDiwan

AmitDiwan

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

254 Views

Let us first create a table −mysql> create table DemoTable    -> (    -> FirstName varchar(20)    -> ); Query OK, 0 rows affected (0.77 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Chris'); Query OK, 1 row affected (0.14 sec) mysql> insert into ... Read More

Wrap around to first value and implement MySQL ORDER BY ASC and DESC in a single query

AmitDiwan

AmitDiwan

Updated on 13-Dec-2019 07:04:30

237 Views

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

Find second max in a table using MySQL query?

AmitDiwan

AmitDiwan

Updated on 13-Dec-2019 07:02:38

595 Views

You can use LIMIT 1 OFFSET 1. Let us first create a table −mysql> create table DemoTable    -> (    -> Value int    -> ); Query OK, 0 rows affected (0.92 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(1); Query OK, 1 ... Read More

MySQL TINYINT type to return <>1 or IS NULL records

AmitDiwan

AmitDiwan

Updated on 13-Dec-2019 07:00:49

741 Views

Let us first create a table −mysql> create table DemoTable    -> (    -> EmployeeId int NOT NULL AUTO_INCREMENT PRIMARY KEY ,    -> EmployeeName varchar(20),    -> isMarried tinyint    -> ); Query OK, 0 rows affected (0.83 sec)Insert some records in the table using insert command −mysql> ... Read More

ERROR 1064 (42000): You have an error in your SQL syntax at zero fill column?

AmitDiwan

AmitDiwan

Updated on 13-Dec-2019 06:57:07

661 Views

Following is the error and it occurs when you implement ZEROFILL incorrectly−mysql> create table DemoTable    -> (    -> StudentCode int(10) NOT NULL ZEROFILL AUTO_INCREMENT PRIMARY KEY    -> ); ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL ... Read More

Find integer in text data (comma separated values) with MySQL?

AmitDiwan

AmitDiwan

Updated on 13-Dec-2019 06:55:11

385 Views

Let us first create a table −mysql> create table DemoTable    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> DoubleValue varchar(20)    -> ); Query OK, 0 rows affected (0.58 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(DoubleValue) values('80.2, 90.5, ... Read More

How to sum a comma separated string (string with numbers) in MySQL?

AmitDiwan

AmitDiwan

Updated on 13-Dec-2019 06:53:01

1K+ Views

You can create a custom function to sum a comma-separated string in MySQL. Let us first create a table. Here, we have a varchar column, wherein we will add numbers in the form of strings −mysql> create table DemoTable    -> (    -> ListOfValues varchar(50)    -> ); Query ... Read More

Get boolean result whether table exists or not using CASE WHEN in MySQL

AmitDiwan

AmitDiwan

Updated on 13-Dec-2019 06:50:08

372 Views

For this, you can use INFORMATION_SCHEMA.TABLES and find the table you want to search. Let us first create a table −mysql> create table DemoTable    -> (    -> Id int,    -> Name varchar(20)    -> ); Query OK, 0 rows affected (1.57 sec)Insert some records in the table ... Read More

Concatenate columns from different tables in MySQL

AmitDiwan

AmitDiwan

Updated on 13-Dec-2019 06:48:11

2K+ Views

You can use CONCAT(). Let us first create a table −mysql> create table DemoTable1    -> (    -> FirstName varchar(20)    -> ); Query OK, 0 rows affected (0.90 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1 values('Chris'); Query OK, 1 row affected (0.12 ... Read More

How to select a field corresponding to the field in which MAX() exists?

AmitDiwan

AmitDiwan

Updated on 13-Dec-2019 06:36:06

144 Views

For this, you can use sub query along with aggregate function MAX(). Let us first create a table −mysql> create table DemoTable    -> (    -> ProductId int,    -> ProductAmount int    -> ); Query OK, 0 rows affected (0.78 sec)Insert some records in the table using insert ... Read More

Advertisements