MySQL Database Field Type for Search Query

AmitDiwan
Updated on 20-Nov-2020 07:21:08

181 Views

Following is the syntax −select *from yourTableName where REGEXP_INSTR(yourColumnName, yourSearchValue);To understand the above syntax, let us first create a table −mysql> create table demo64 −> ( −> id int not null auto_increment primary key, −> name varchar(40) −> ); Query OK, 0 rows affected (3.06 sec)Insert some records into the table with the help of insert command −mysql> insert into demo64(name) values('John Smith'); Query OK, 1 row affected (0.21 sec) mysql> insert into demo64(name) values('John Doe'); Query OK, 1 row affected (0.15 sec) mysql> insert into demo64(name) values('Chris Brown'); Query OK, 1 row affected (0.08 sec) mysql> ... Read More

Encrypt and Decrypt a String in MySQL

AmitDiwan
Updated on 20-Nov-2020 07:18:17

7K+ Views

To encrypt and decrypt in MySQL, use the AES_ENCRYPT() and AES_DECRYPT() in MySQL −insert into yourTableName values(AES_ENCRYPT(yourValue, yourSecretKey)); select cast(AES_DECRYPT(yourColumnName, yourSecretKey) as char) from yourTableName;To understand the above syntax, let us first create a table −mysql> create table demo63 −> ( −> value blob −> ); Query OK, 0 rows affected (2.60 sec)Insert some records into the table with the help of insert command. We are encrypting while inserting −mysql> insert into demo63 values(AES_ENCRYPT('John', 'PASS')); Query OK, 1 row affected (0.18 sec) mysql> insert into demo63 values(AES_ENCRYPT('David', 'PASS')); Query OK, 1 row affected (0.41 sec) mysql> insert ... Read More

Add Row to Table Using Strings from Another Table in MySQL

AmitDiwan
Updated on 20-Nov-2020 07:16:20

213 Views

For this, use INSERT INTO SELECT statement in MySQL. Let us create a table −mysql> create table demo61 −> ( −> id int, −> name varchar(20) −> ) −> ; Query OK, 0 rows affected (1.84 sec)Insert some records into the table with the help of insert command −mysql> insert into demo61 values(1, 'John'); Query OK, 1 row affected (0.63 sec) mysql> insert into demo61 values(2, 'David'); Query OK, 1 row affected (0.13 sec) mysql> insert into demo61 values(1, 'Mike'); Query OK, 1 row affected (0.10 sec) mysql> insert into demo61 values(2, 'Carol'); Query OK, 1 row ... Read More

Select WHERE IN NULL in MySQL

AmitDiwan
Updated on 20-Nov-2020 07:14:04

528 Views

Following is the syntax −select yourColumnName1, yourColumnName2, yourColumnName3, . . . N from yourTableName where yourValue in(yourColumnName1, yourColumnName2) or yourColumnName1 is NULL;Let us create a table −mysql> create table demo60 −> ( −> id int not null auto_increment primary key, −> first_name varchar(20), −> last_name varchar(20) −> ) −> ; Query OK, 0 rows affected (2.11 sec)Insert some records into the table with the help of insert command −mysql> insert into demo60(first_name, last_name) values('John', 'Smith'); Query OK, 1 row affected (0.09 sec) mysql> insert into demo60(first_name, last_name) values('John', 'Doe'); Query OK, 1 row affected (0.51 sec) mysql> insert ... Read More

Change Value of Decimal 19,2 When Inserting into Database in MySQL

AmitDiwan
Updated on 20-Nov-2020 07:10:41

204 Views

To store the exact real value, you need to use truncate() with 2 decimal point. Let us create a table −Following is the query to create a table.mysql> create table demo59 −> ( −> price decimal(19, 2) −> ); Query OK, 0 rows affected (1.12 sec)Insert some records into the table with the help of insert command −mysql> insert into demo59 values(truncate(15.346, 2)); Query OK, 1 row affected (0.14 sec) mysql> insert into demo59 values(truncate(20.379, 2)); Query OK, 1 row affected (0.72 sec) mysql> insert into demo59 values(truncate(25.555, 2)); Query OK, 1 row affected (0.16 sec) mysql> ... Read More

Expression in CASE WHEN Clause in MySQL Query

AmitDiwan
Updated on 20-Nov-2020 07:09:22

284 Views

Fir this, use CASE WHEN statement in MySQL correctly. Let us see how.Let us create a table −mysql> create table demo58 −> ( −> id int not null auto_increment primary key, −> first_name varchar(20), −> last_name varchar(20) −> ); Query OK, 0 rows affected (2.15 sec)Insert some records into the table with the help of insert command −mysql> insert into demo58(first_name, last_name) values('John', 'Doe'); Query OK, 1 row affected (0.12 sec) mysql> insert into demo58(first_name, last_name) values('David', 'Smith'); Query OK, 1 row affected (0.29 sec) mysql> insert into demo58(first_name, last_name) values('John', 'Brown'); Query OK, 1 row affected (0.11 ... Read More

Sort a Particular Value at the End in MySQL

AmitDiwan
Updated on 20-Nov-2020 07:06:57

137 Views

For this, you can use ORDER BY. Let us create a table −mysql> create table demo57 −> ( −> id int not null auto_increment primary key, −> full_name varchar(20) −> ); Query OK, 0 rows affected (1.60 sec)Insert some records into the table with the help of insert command −mysql> insert into demo57(full_name) values('John Smith'); Query OK, 1 row affected (0.24 sec) mysql> insert into demo57(full_name) values('David Miller'); Query OK, 1 row affected (0.13 sec) mysql> insert into demo57(full_name) values('Not Known'); Query OK, 1 row affected (0.13 sec) mysql> insert into demo57(full_name) values('Chris Brown'); Query OK, 1 ... Read More

Multiple Data Input at the Same Time in MySQL

AmitDiwan
Updated on 20-Nov-2020 07:05:18

825 Views

Following is the syntax −insert into yourTableName values(yourValue1, yourValue2, .....N), (yourValue1, yourValue2, .....N), (yourValue1, yourValue2, .....N), (yourValue1, yourValue2, .....N), . . . NLet us create a table −mysql> create table demo56 −> ( −> id int, −> first_name varchar(20), −> last_name varchar(20), −> age int −> ); Query OK, 0 rows affected (1.91 sec)Insert some records into the table with the help of insert command −mysql> insert into demo56 values(1, 'John', 'Smith', 23), −> (2, 'David', 'Miller', 21), −> (3, 'Chris', 'Brown', 22), −> (4, 'Carol', 'Taylor', 20); Query OK, 4 rows affected (0.10 sec) Records: 4 Duplicates: 0 Warnings: ... Read More

Update Data in One Table from Another Table in MySQL

AmitDiwan
Updated on 20-Nov-2020 07:03:10

1K+ Views

For this, you can use UPDATE command along with JOIN.Let us create the first table −mysql> create table demo54 −> ( −> firstName varchar(20), −> lastName varchar(20) −> ); Query OK, 0 rows affected (0.57 sec)Insert some records into the table with the help of insert command −mysql> insert into demo54 values('John', 'Smith'); Query OK, 1 row affected (0.09 sec) mysql> insert into demo54 values('John', 'Smith'); Query OK, 1 row affected (0.09 sec) mysql> insert into demo54 values('David', 'Smith'); Query OK, 1 row affected (0.11 sec)Display records from the table using select statement −mysql> select *from demo54;This will ... Read More

Fill Min-Max Game Tree in Python

Arnab Chakraborty
Updated on 20-Nov-2020 05:55:51

3K+ Views

Suppose we have a binary tree representing a game state of a two player game. Every internal node is filled with 0 and the leaves values represent the end score. Player 1 wants to maximize the end score while player 2 wants to minimize the end score. Player 1 will always make moves on nodes at even levels and player 2 will always make moves on odd levels. We have to fill in the binary tree with the resulting scores assuming both of players play optimally.So, if the input is likethen the output will beTo solve this, we will follow ... Read More

Advertisements