AmitDiwan has Published 8358 Articles

How to cast and update a numeric value from string column only where applicable in MySQL?

AmitDiwan

AmitDiwan

Updated on 12-Dec-2019 05:59:36

570 Views

You can use the CEIL() function from MySQL. Let us first create a table. Here, we have taken the first column as VARCHAR −mysql> create table DemoTable    -> (    -> Value varchar(20),    -> UpdateValue int    -> ); Query OK, 0 rows affected (1.08 sec)Insert some records ... Read More

MySQL query to remove string from a column with values EMP1, EMP2, EMP3, etc.

AmitDiwan

AmitDiwan

Updated on 12-Dec-2019 05:56:34

327 Views

To remove string from the values EMO1, EMP2, etc., you need to use RIGHT() along with LENGTH(). Let us first create a table −mysql> create table DemoTable1540    -> (    -> EmployeeCode varchar(20)    -> ); Query OK, 0 rows affected (0.39 sec)Insert some records in the table using ... Read More

MySQL DATE function to return the difference between current date and joining date

AmitDiwan

AmitDiwan

Updated on 12-Dec-2019 05:55:13

1K+ Views

At first, find the current date and get the difference between joining date and current date using the DATEDIFF().The current date is as follows −mysql> select curdate(); +------------+ |  curdate() | +------------+ | 2019-10-26 | +------------+ 1 row in set (0.00 sec)Let us first create a table −mysql> create table ... Read More

Combine columns into rows with MySQL?

AmitDiwan

AmitDiwan

Updated on 12-Dec-2019 05:52:42

2K+ Views

To combine columns into rows, use UNION ALL. Following is the syntax −Syntaxselect yourColumnName1 from yourTableName    union all select yourColumnName2 from yourTableName;Let us first create a table −mysql> create table DemoTable    -> (    -> Value1 int,    -> Value2 int    -> ); Query OK, 0 rows ... Read More

Should I use a loop or 'OR' operator to query a bunch of stuff at a fast pace In MYSQL?

AmitDiwan

AmitDiwan

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

146 Views

For faster querying, you need to use MySQL IN(). Let us first create a table −mysql> create table DemoTable1538    -> (    -> ClientId int,    -> ClientName varchar(20)    -> ); Query OK, 0 rows affected (0.59 sec)Insert some records in the table using insert command −mysql> insert ... Read More

How to create a column of months from date and display sum of the corresponding column wherein you find duplicate dates?

AmitDiwan

AmitDiwan

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

108 Views

For this can use DATE_FORMAT() in MySQL. Let us first create a table −mysql> create table DemoTable    -> (    -> PurchaseDate date,    -> Amount int    -> ); Query OK, 0 rows affected (0.52 sec)Insert some records in the table using insert command −mysql> insert into DemoTable ... Read More

How to write a single MySQL query for displaying a value for multiple inputs?

AmitDiwan

AmitDiwan

Updated on 12-Dec-2019 05:47:28

366 Views

For this, use BETWEEN keyword. Let us first create a table −mysql> create table DemoTable1537    -> (    -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> StudentName varchar(20)    -> ); Query OK, 0 rows affected (0.72 sec)Insert some records in the table using insert command −mysql> ... Read More

Using Update statement with TINYINT in MySQL?

AmitDiwan

AmitDiwan

Updated on 12-Dec-2019 05:46:35

2K+ Views

Let us first create a table. We have set one of the columns with type TINYINT −mysql> create table DemoTable    -> (    -> EmployeeId int,    -> isMarried tinyint    -> ); Query OK, 0 rows affected (6.84 sec)Insert some records in the table using insert command −mysql> ... Read More

A single MySQL query to search multiple words from different column values

AmitDiwan

AmitDiwan

Updated on 12-Dec-2019 05:44:51

2K+ Views

For this, you can use WHERE clause with multiple LIKE. Let us first create a table −mysql> create table DemoTable1536    -> (    -> Sentence text    -> ); Query OK, 0 rows affected (0.51 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1536 values('I ... Read More

MySQL Order by beginning letter?

AmitDiwan

AmitDiwan

Updated on 12-Dec-2019 05:42:42

668 Views

To order by the first letter, use ORDER BY CASE statement. Let us first create a table −mysql> create table DemoTable1535    -> (    -> Value varchar(100)    -> ); Query OK, 0 rows affected (2.26 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1535 ... Read More

Advertisements