AmitDiwan has Published 11365 Articles

Order dates in MySQL with the format “01 August 2019”?

AmitDiwan

AmitDiwan

Updated on 12-Nov-2019 06:42:24

62 Views

To display dates like “01 August 2019”, use ORDER BY STR_TO_DATE(). Let us first create a −mysql> create table DemoTable1435    -> (    -> DueDate varchar(60)    -> ); Query OK, 0 rows affected (1.08 sec)Insert some records in the table using insert −mysql> insert into DemoTable1435 values('01 August ... Read More

Insert current time minus 1 hour to already inserted date-time records in MYSQL

AmitDiwan

AmitDiwan

Updated on 12-Nov-2019 06:40:43

701 Views

For subtracting dates, use MySQL DATE_SUB(). Let us first create a −mysql> create table DemoTable1434    -> (    -> ArrivalDatetime datetime    -> ); Query OK, 0 rows affected (3.14 sec)Insert some records in the table using insert −mysql> insert into DemoTable1434 values('2019-09-30 21:10:00'); Query OK, 1 row affected ... Read More

Store strings in variables and concatenate them to display them in a single column in MYSQL

AmitDiwan

AmitDiwan

Updated on 12-Nov-2019 06:39:07

204 Views

For this, use CONCAT_WS() in MySQL. Let us first create a −mysql> create table DemoTable1433    -> (    -> ClientId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> ClientFirstName varchar(20),    -> ClientLastName varchar(20)    -> ); Query OK, 0 rows affected (0.58 sec)Insert some records in the table ... Read More

Fetch specific rows from a MySQL table with duplicate column values (names)?

AmitDiwan

AmitDiwan

Updated on 12-Nov-2019 06:32:50

92 Views

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

Append special characters to column values in MySQL

AmitDiwan

AmitDiwan

Updated on 12-Nov-2019 06:29:55

457 Views

Let us first create a −mysql> create table DemoTable1626    -> (    -> Name varchar(20)    -> ); Query OK, 0 rows affected (0.37 sec)Insert some records in the table using insert −mysql> insert into DemoTable1626 values('Chris'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1626 values('Bob'); ... Read More

Select count of values (Yes, No) with same ids but different corresponding records in MySQL?

AmitDiwan

AmitDiwan

Updated on 12-Nov-2019 06:28:38

569 Views

For this, you can use SUM() along with CASE statement. Let us first create a −mysql> create table DemoTable1430    -> (    -> EmployeeId int,    -> isMarried ENUM('YES', 'NO')    -> ); Query OK, 0 rows affected (0.60 sec)Insert some records in the table using insert −mysql> insert ... Read More

Fetch date records comparing with the current date’s day and month in MySQL

AmitDiwan

AmitDiwan

Updated on 12-Nov-2019 06:25:00

114 Views

For this, use MONTH() and DAY(). Let us first create a −mysql> create table DemoTable1429    -> (    -> AnniversaryDate date    -> );Insert some records in the table using insert −mysql> insert into DemoTable1429 values('2019-09-29'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable1429 values('2018-09-27'); Query ... Read More

Count the number of comma’s in every record from a comma-separated value column in MySQL

AmitDiwan

AmitDiwan

Updated on 12-Nov-2019 06:23:46

1K+ Views

Let us first create a −mysql> create table DemoTable1510    -> (    -> Value varchar(50)    -> ); Query OK, 0 rows affected (6.75 sec)Insert some records in the table using insert −mysql> insert into DemoTable1510 values('20, 35'); Query OK, 1 row affected (0.57 sec) mysql> insert into DemoTable1510 ... Read More

Filter column value by the first character in MySQL

AmitDiwan

AmitDiwan

Updated on 12-Nov-2019 06:22:16

1K+ Views

You can use LEFT() from MySQL. Let us first create a −mysql> create table DemoTable1428    -> (    -> EmployeeId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> EmployeeName varchar(20)    -> ); Query OK, 0 rows affected (1.05 sec)Insert some records in the table using insert −mysql> insert ... Read More

Exclude rows based on column value when another duplicate column value is found in MySQL?

AmitDiwan

AmitDiwan

Updated on 12-Nov-2019 06:20:43

393 Views

For this, you can use subquery. Let us first create a −mysql> create table DemoTable1427    -> (    -> StudentId int,    -> StudentMarks int    -> ); Query OK, 0 rows affected (1.28 sec)Insert some records in the table using insert −mysql> insert into DemoTable1427 values(201, 89); Query ... Read More

Advertisements