AmitDiwan has Published 10744 Articles

How to convert a date format in MySQL?

AmitDiwan

AmitDiwan

Updated on 02-Jan-2020 06:07:10

543 Views

To convert a date format, use STR_TO_DATE() −mysql> create table DemoTable2010 (    DueDate varchar(20) ); Query OK, 0 rows affected (0.68 sec)Insert some records in the table using insert command −mysql> insert into DemoTable2010 values('12/10/2019 12:34:00'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable2010 values('12/12/2011 11:00:20'); ... Read More

Using LIKE clause twice in a MySQL query

AmitDiwan

AmitDiwan

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

412 Views

Let us first create a table −mysql> create table DemoTable2009 (    Name varchar(20) ); Query OK, 0 rows affected (0.51 sec)Insert some records in the table using insert command −mysql> insert into DemoTable2009 values('John Doe'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable2009 values('Adam Smith'); Query ... Read More

Set custom messages by working with MySQL IF Statements and SELECT in a user-defined variable

AmitDiwan

AmitDiwan

Updated on 02-Jan-2020 06:04:30

232 Views

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

MySQL query to insert multiple records quickly

AmitDiwan

AmitDiwan

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

372 Views

To insert multiple records quickly, use a single INSERT and follow the below syntax −insert into yourTableName values(yourValue1, yourValue2, ...N), (yourValue1, yourValue2, ...N).....N;To understand the above syntax, let us create a table −mysql> create table DemoTable2007 (    Amount1 int,    Amount2 int,    Amount3 int ); Query OK, 0 ... Read More

Fetch a specific record from a column with string values (string, numbers and special characters) in MySQL

AmitDiwan

AmitDiwan

Updated on 02-Jan-2020 05:55:39

446 Views

For this, you can use ORDER BY CAST(). Let us see an example −mysql> create table DemoTable2006 (    UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    UserCode    varchar(20) ); Query OK, 0 rows affected (1.14 sec)Insert some records in the table using insert command −mysql> insert into DemoTable2006(UserCode) ... Read More

Get minimum value from a column (floating values) with corresponding duplicate ids in MySQL

AmitDiwan

AmitDiwan

Updated on 02-Jan-2020 05:51:53

391 Views

To get minimum value from a column with corresponding duplicate ids, use GROUP BY and MIN() −select min(yourColumnName) from yourTableName group by yourColumnName;To understand the above syntax, let us create a table −mysql> create table DemoTable2005 (    Id int,    Price float ); Query OK, 0 rows affected (0.71 ... Read More

Use IN() to get only a particular record in a MySQL stored procedure?

AmitDiwan

AmitDiwan

Updated on 02-Jan-2020 05:48:41

229 Views

Let us first create a table −mysql> create table DemoTable2004 (    UserId varchar(20),    UserName varchar(20) ); Query OK, 0 rows affected (0.57 sec)Insert some records in the table using insert command −mysql> insert into DemoTable2004 values('John_123', 'John'); Query OK, 1 row affected (0.93 sec) mysql> insert into DemoTable2004 ... Read More

Display highest amount from corresponding duplicate ids in MySQL

AmitDiwan

AmitDiwan

Updated on 02-Jan-2020 05:46:16

871 Views

To display highest amount from corresponding duplicate ids, use MAX() along with GROUP BY clause −mysql> create table DemoTable2003 (    CustomerId int,    Amount int ); Query OK, 0 rows affected (0.65 sec)Insert some records in the table using insert command −mysql> insert into DemoTable2003 values(101, 560); Query OK, ... Read More

Display records by grouping dates in MySQL

AmitDiwan

AmitDiwan

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

150 Views

To group dates in MySQL, use the GROUP BY clause −mysql> create table DemoTable2002 (    CustomerName varchar(20),    CustomerShippingDate datetime ); Query OK, 0 rows affected (0.61 sec)Insert some records in the table using insert command −mysql> insert into DemoTable2002 values('Chris', '2019-01-10'); Query OK, 1 row affected (0.17 sec) ... Read More

Get the maximum exam date using a user-defined variable in SQL

AmitDiwan

AmitDiwan

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

107 Views

To get the maximum exam date with a user-defined variable, the code is as follows −select date(max(yourColumnName )) into @yourVariableName  from yourTableName;To understand the above syntax, let us first create a table −mysql> create table DemoTable2001 (    ExamDate date ); Query OK, 0 rows affected (0.60 sec)Insert some records ... Read More

Advertisements