AmitDiwan has Published 10744 Articles

Calculating power of a number in MySQL?

AmitDiwan

AmitDiwan

Updated on 22-Aug-2019 07:39:06

119 Views

To calculate power of a number, use POWER() function. Let us first create a table −mysql> create table DemoTable    (       Amount int    ); Query OK, 0 rows affected (0.89 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(64); Query OK, ... Read More

Convert UK DATE to MySQL date?

AmitDiwan

AmitDiwan

Updated on 22-Aug-2019 07:36:41

402 Views

The UK date format supports day-moth-year format. To convert it to MySQL date, use STR_TO_DATE(). Following is the syntax:select str_to_date(yourColumnName, '%d/%m/%Y') from yourTableName;Let us first create a table:mysql> create table DemoTable728 (DueDate varchar(100)); Query OK, 0 rows affected (0.59 sec)Insert some records in the table using insert command:mysql> insert into ... Read More

Selecting a value in custom order from another column in a MySQL table with a single query

AmitDiwan

AmitDiwan

Updated on 22-Aug-2019 07:35:16

144 Views

For this, you can use IN().Let us first create a table:mysql> create table DemoTable727 (    Name varchar(100),    Score int ); Query OK, 0 rows affected (0.88 sec)Insert some records in the table using insert command:mysql> insert into DemoTable727 values('Chris', 45); Query OK, 1 row affected (0.18 sec) mysql> ... Read More

Replace date format with MySQL STR_TO_DATE

AmitDiwan

AmitDiwan

Updated on 22-Aug-2019 07:33:37

457 Views

Let us first create a table −mysql> create table DemoTable(DueDate varchar(100)); Query OK, 0 rows affected (0.78 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('10-01-2019 10:19:20'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('12-03-2018 11:00:00'); Query OK, 1 row affected ... Read More

How to sort varchar numeric columns by DESC or ASC in MySQL?

AmitDiwan

AmitDiwan

Updated on 22-Aug-2019 07:33:35

537 Views

Let us first create a table −mysql> create table DemoTable726 (Value varchar(100)); Query OK, 0 rows affected (0.60 sec)Insert some records in the table using insert command −mysql> insert into DemoTable726 values('100'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable726 values('10'); Query OK, 1 row affected (0.15 ... Read More

Can we give underscore in a MySQL table name?

AmitDiwan

AmitDiwan

Updated on 22-Aug-2019 07:31:45

1K+ Views

You cannot give underscore in table name. If you still want to create a new table with underscore, surround it using backticks, not single quotes.However, let us first try to set quotes around a table name with underscore. Following is an example −mysql> create table 'Demo_Table725'(    ClientId int NOT ... Read More

MySQL query to select bottom n records

AmitDiwan

AmitDiwan

Updated on 22-Aug-2019 07:29:07

1K+ Views

Let us first create a table −mysql> create table DemoTable724 (Value int); Query OK, 0 rows affected (0.79 sec)Insert some records in the table using insert command −mysql> insert into DemoTable724 values(101); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable724 values(183); Query OK, 1 row affected (0.15 ... Read More

Select a value from MySQL database only if it exists only once from a column with duplicate and non-duplicate values

AmitDiwan

AmitDiwan

Updated on 22-Aug-2019 07:27:37

475 Views

Let us first create a table −mysql> create table DemoTable723 (Value int); Query OK, 0 rows affected (0.58 sec)Insert some records in the table using insert command −mysql> insert into DemoTable723 values(100); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable723 values(200); Query OK, 1 row affected (0.13 ... Read More

REGEX in MySQL to display only numbers separated by hyphen.

AmitDiwan

AmitDiwan

Updated on 22-Aug-2019 07:26:32

435 Views

Let us first create a table −mysql> create table DemoTable    (       Code varchar(100)    ); Query OK, 0 rows affected (1.16 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('100-677-9876'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable ... Read More

Is there a way to list all the reserved words in MySQL using the MySQL command-line utility?

AmitDiwan

AmitDiwan

Updated on 22-Aug-2019 07:26:07

210 Views

Yes, we can all the reserved words in MySQL using the command-line utility. Following is the syntax −select *from mysql.help_keyword;Let us implement the above syntax in order to get list of all the reserved words in MySQL.Following is the query −mysql> select *from mysql.help_keyword;This will produce the following output -Read More

Advertisements