AmitDiwan has Published 10740 Articles

Get the minimum and maximum value from a VARCHAR column and display the result in separate MySQL columns?

AmitDiwan

AmitDiwan

Updated on 26-Sep-2019 07:51:01

572 Views

Let us first create a table −mysql> create table DemoTable (    Value varchar(100) ); Query OK, 0 rows affected (0.75 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('190'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('230'); Query OK, 1 ... Read More

Perform MySQL SELECT on dates inserted into the table as VARCHAR values

AmitDiwan

AmitDiwan

Updated on 26-Sep-2019 07:48:46

130 Views

Let us first create a table −mysql> create table DemoTable (    DueDate varchar(100) ); Query OK, 0 rows affected (0.50 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('21/10/2018'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable values('18/08/2019'); Query OK, 1 ... Read More

Copy column values from one table into another matching IDs in MySQL

AmitDiwan

AmitDiwan

Updated on 26-Sep-2019 07:46:51

1K+ Views

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

MySQL CONCAT a specific column value with the corresponding record

AmitDiwan

AmitDiwan

Updated on 26-Sep-2019 07:43:56

166 Views

Let us first create a table −mysql> create table DemoTable (    FirstName varchar(100),    CountryName varchar(100) ); Query OK, 0 rows affected (0.56 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Adam', 'US'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable ... Read More

INSERT INTO table if a table exists in MySQL else implement CREATE TABLE and create the table

AmitDiwan

AmitDiwan

Updated on 26-Sep-2019 07:41:48

1K+ Views

Here’s the syntax to check whether the table already exists using the CREATE TABLE IF NOT EXISTS −create table if not exists yourTableName (    yourColumnName1 dataType,    .    .    .    .    N ); insert into yourTableName values(yourValue1, .......N);Let us first create a table −mysql> create ... Read More

How to find a specific record from a list of values with semicolon in MySQL?

AmitDiwan

AmitDiwan

Updated on 26-Sep-2019 07:38:20

148 Views

For this, you can use FIND_IN_SET(). Let us first create a table −mysql> create table DemoTable (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Value varchar(100) ); Query OK, 0 rows affected (2.49 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Value) values('100;200;300'); Query ... Read More

MySQL query to order timestamp in descending order but place the timestamp 0000-00-00 00:00:00 first?

AmitDiwan

AmitDiwan

Updated on 26-Sep-2019 07:36:06

1K+ Views

Let us first create a table &mnus;mysql> create table DemoTable (    `timestamp` timestamp ); Query OK, 0 rows affected (1.12 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(now()); Query OK, 1 row affected (0.27 sec) mysql> insert into DemoTable values('00:00:00'); Query OK, 1 ... Read More

MySQL group_concat to add a separator for empty fields?

AmitDiwan

AmitDiwan

Updated on 26-Sep-2019 07:33:08

445 Views

For this, you can use replace() along with group_concat(). Here, for empty fields, we are displaying a comma as a separator. Let us first create a table −mysql> create table DemoTable (    Id int,    Number varchar(100) ); Query OK, 0 rows affected (2.03 sec)Insert some records in the ... Read More

How to ORDER BY DESC and display the first 3 records in MySQL?

AmitDiwan

AmitDiwan

Updated on 26-Sep-2019 07:29:43

679 Views

For this, you can use ORDER BY DESC with LIMIT. Let us first create a table −mysql> create table DemoTable (    UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    UserName varchar(100) ); Query OK, 0 rows affected (0.59 sec)Insert some records in the table using insert command −mysql> insert ... Read More

MySQL ORDER BY strings with underscore?

AmitDiwan

AmitDiwan

Updated on 26-Sep-2019 07:27:27

365 Views

Let us first create a table −mysql> create table DemoTable (    Name varchar(100) ); Query OK, 0 rows affected (0.60 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('John_Smith'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('Chris Brown'); Query OK, ... Read More

Advertisements