AmitDiwan has Published 10744 Articles

Difference between intvalue='1' and intvalue=1 in MySQL?

AmitDiwan

AmitDiwan

Updated on 12-Dec-2019 06:58:34

79 Views

You need to use intvalue=1. The statement intvalue=’1’ is internally converted to cast(‘1’ as int) by MySQL.Let us first create a table −mysql> create table DemoTable1566    -> (    -> intvalue int    -> ); Query OK, 0 rows affected (0.64 sec)Insert some records in the table using insert ... Read More

MySQL query not matching due to punctuation?

AmitDiwan

AmitDiwan

Updated on 12-Dec-2019 06:57:43

127 Views

Use the MySQL LIKE operator to match even when punctuation is present. Let us first create a table−mysql> create table DemoTable    -> (    -> Comments varchar(20)    -> ); Query OK, 0 rows affected (1.10 sec)Insert some records in the table using insert command −mysql> insert into DemoTable ... Read More

Convert from varchar to datetime and compare in MySQL?

AmitDiwan

AmitDiwan

Updated on 12-Dec-2019 06:56:00

2K+ Views

For this, you can use STR_TO_DATE(). Let us first create a table −mysql> create table DemoTable1565    -> (    -> ArrivalDatetime varchar(40)    -> ); Query OK, 0 rows affected (0.82 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1565 values('10/01/2019 21:29:35'); Query OK, 1 ... Read More

CASE WHEN column1 IS NULL THEN NULL ELSE column2 END with MySQL

AmitDiwan

AmitDiwan

Updated on 12-Dec-2019 06:55:06

2K+ Views

For this, you can use the CASE statement. Let us first create a table−mysql> create table DemoTable    -> (    -> Name varchar(20),    -> Marks1 int,    -> Marks2 int    -> ); Query OK, 0 rows affected (0.72 sec)Insert some records in the table using insert command−mysql> ... Read More

How to make MySQL result set the same as specified?

AmitDiwan

AmitDiwan

Updated on 12-Dec-2019 06:52:37

132 Views

For this, use MySQL FIND_IN_SET(). Let us first create a table −mysql> create table DemoTable1563    -> (    -> StudentId int,    -> StudentName varchar(20)    -> ); Query OK, 0 rows affected (0.52 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1563 values(1001, 'Chris'); ... Read More

Sorting max to min value in MySQL

AmitDiwan

AmitDiwan

Updated on 12-Dec-2019 06:51:34

840 Views

To sort from max to min value, use ORDER BY length(). Let us first create a table −mysql> create table DemoTable    -> (    -> Price varchar(20)    -> ); Query OK, 0 rows affected (0.92 sec)Insert some records in the table using insert command −mysql> insert into DemoTable ... Read More

Should I name the username field in my MySQL table “name” or “user_name”?

AmitDiwan

AmitDiwan

Updated on 12-Dec-2019 06:50:43

446 Views

Do not prefix table name with field name like user_name. Instead, use user or username.If you prefix table name, then there may be a chance of ambiguity, so avoid prefixing table name.Let us first create a table −mysql> create table user    -> (    -> username varchar(20),    -> ... Read More

Counting voucher value total since the beginning of the month and year in MySQL

AmitDiwan

AmitDiwan

Updated on 12-Dec-2019 06:49:05

135 Views

For this, use MySQL MONTH() and YEAR() methods. Let us first create a table −mysql> create table DemoTable1562    -> (    -> VoucherValue int,    -> RechargeDate date    -> ); Query OK, 0 rows affected (1.40 sec)Insert some records in the table using insert command −mysql> insert into ... Read More

MySQL query to fetch multiple least values?

AmitDiwan

AmitDiwan

Updated on 12-Dec-2019 06:48:21

180 Views

For this, you can use a sub query along with MIN(). Let us first create a table−mysql> create table DemoTable    -> (    -> Name varchar(20),    -> Score int    -> ); Query OK, 0 rows affected (0.56 sec)Insert some records in the table using insert command −mysql> ... Read More

What's the most efficient way to pull data from MySQL so that it is formatted with duplicate values

AmitDiwan

AmitDiwan

Updated on 12-Dec-2019 06:46:56

132 Views

For this, you can use GROUP_CONCAT(). Let us first create a table −mysql> create table DemoTable1561    -> (    -> StudentName varchar(20),    -> Title text    -> ); Query OK, 0 rows affected (0.60 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1561 values('Adam', ... Read More

Advertisements