AmitDiwan has Published 10744 Articles

MySQL isn’t displaying right single quotation mark(’) after insertion of records

AmitDiwan

AmitDiwan

Updated on 02-Jan-2020 05:37:56

371 Views

To display right single quotation marks, you need to alter the table with COLLATE='utf8_unicode_ci'.Let us first create a table −mysql> create table DemoTable2000 (    Name varchar(20) ); Query OK, 0 rows affected (0.81 sec)Here is the query to use collate −mysql> ALTER TABLE DemoTable2000 COLLATE='utf8_unicode_ci'; Query OK, 0 rows ... Read More

Convert DATE timestamp to return only the month name in MySQL

AmitDiwan

AmitDiwan

Updated on 02-Jan-2020 05:35:56

218 Views

To return only the month name, you can use DATE_FORMAT() −mysql> create table DemoTable1999 (    ArrivalDate timestamp ); Query OK, 0 rows affected (0.66 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1999 values('2019-01-01 12:34:00'); Query OK, 1 row affected (0.18 sec) mysql> insert into ... Read More

Return only a single row from duplicate rows with MySQL

AmitDiwan

AmitDiwan

Updated on 02-Jan-2020 05:33:52

1K+ Views

To return only a single row from duplicate rows, use DISTINCT keyword −mysql> create table DemoTable1998 (    Name varchar(20) ); Query OK, 0 rows affected (0.61 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1998 values('Robert'); Query OK, 1 row affected (0.17 sec) mysql> insert ... Read More

MySQL - Convert YYYY-MM-DD to UNIX timestamp

AmitDiwan

AmitDiwan

Updated on 02-Jan-2020 05:32:04

823 Views

To convert date to UNIX timestamp, use UNIX_TIMESTAMP() in MySQL −mysql> create table DemoTable1997 (    DueDate date ); Query OK, 0 rows affected (0.58 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1997 values('2018-10-11'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1997 ... Read More

Display distinct column name in MySQL

AmitDiwan

AmitDiwan

Updated on 02-Jan-2020 05:29:29

225 Views

Let us create a table −mysql> create table DemoTable1996 (    ShippingDate datetime,    CustomerName varchar(20) ); Query OK, 0 rows affected (0.84 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1996 values('2019-12-21 10:45:00', 'Chris'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1996 ... Read More

Add 11 days to current date in MySQL

AmitDiwan

AmitDiwan

Updated on 02-Jan-2020 05:27:36

425 Views

Let us first create a table −mysql> create table DemoTable1994 (    ArrivalDate date ); Query OK, 0 rows affected (5.33 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1994 values('2019-12-18'); Query OK, 1 row affected (0.47 sec) mysql> insert into DemoTable1994 values('2019-12-19'); Query OK, 1 ... Read More

Set custom messages for enum values in MySQL

AmitDiwan

AmitDiwan

Updated on 02-Jan-2020 05:25:01

181 Views

Use the if else to set custom messages for enum. Let us first create a table −mysql> create table DemoTable1992 (    ClientId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    ClientName varchar(20),    isActive ENUM('Y', 'N') ); Query OK, 0 rows affected (0.89 sec)Insert some records in the table using ... Read More

Select from table where value does not exist with MySQL?

AmitDiwan

AmitDiwan

Updated on 02-Jan-2020 05:22:00

850 Views

For this, you can use NOT IN() −mysql> create table DemoTable1991 (    StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    StudentName varchar(20) ); Query OK, 0 rows affected (0.61 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1991(StudentName) values('Chris'); Query OK, 1 row affected (0.24 ... Read More

MySQL - Select dates that are one week ahead from today?

AmitDiwan

AmitDiwan

Updated on 02-Jan-2020 05:19:12

341 Views

To get dates that are one week ahead from today, use DATEDIFF. Let us first get the current date −mysql> select curdate(); +------------+ | curdate()  | +------------+ | 2019-12-20 | +------------+ 1 row in set (0.00 sec)We will first create a table −mysql> create table DemoTable1990    (    ShippingDate ... Read More

Convert VARCHAR data to MySQL date format?

AmitDiwan

AmitDiwan

Updated on 02-Jan-2020 05:17:18

727 Views

To convert VARCHAR data to date format, you can use STR_TO_DATE() −mysql> create table DemoTable1989    (    DueDate varchar(20)    ); Query OK, 0 rows affected (0.91 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1989 values('31/01/2015'); Query OK, 1 row affected (0.52 sec) mysql> ... Read More

Advertisements