MySQL Articles - Page 23 of 439

What is the execution result when non-SQL changes are made in the program without BIND?

Mandalika
Updated on 01-Dec-2020 05:03:14

243 Views

Problem: A COBOL-DB2 program is changed to increase the length of a variable from PIC X(5) to PIC X(8). However, there are no changes in the SQL of the program. What will be the result if the program's plan/package is not binded for these changes?SolutionThe variable length change from PIC X(5) to PIC X(8) is not a DB2 change and there are no modifications required for SQL statements in the program. However, still we need to BIND its PLAN/PACKAGE else we will get SQL error code -818 which states that “THE PRECOMPILER-GENERATED TIMESTAMP x IN THE LOAD MODULE IS DIFFERENT ... Read More

Example of SQL query describing COUNT function and GROUP BY

Mandalika
Updated on 01-Dec-2020 04:49:56

367 Views

Problem: Write a query on TRANSACTIONS DB2 table to list down the number of orders (ORDER_ID) assigned to a particular transaction (TRANSACTION_ID).SolutionWe can use the below query to find out the number of orders assigned to a particular transaction id on TRANSACTIONS DB2 table.ExampleSELECT TRANSACTION_ID, COUNT(ORDER_ID) FROM TRANSACTIONS    GROUP BY TRANSACTION_IDWe will use GROUP BY function on the ORDER_ID to fetch the result order wise. The COUNT function will count the number of orders. For example, we have below DB2 ORDERS table.TRANSACTION_IDORDER_IDIRN22345A23118IRN22345A45901IRN22345A67990IRN56902A23119IRN99781A67921IRN56902A23167 The result of our DB2 query will return the below result.TRANSACTION_IDCOUNT(ORDER_ID)IRN223453IRN569022IRN997811Read More

How does spring boot connect localhost MySQL

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

2K+ Views

For this, use application.properties −spring.datasource.username=yourMySQLUserName spring.datasource.password=yourMySQLPassword spring.datasource.url=jdbc:mysql://localhost:3306/yoruDatabaseName spring.datasource.driver-class-name=com.mysql.cj.jdbc.DriverTo understand the above syntax, let us create a table −mysql> create table demo71 −> ( −> id int, −> name varchar(20) −> ); Query OK, 0 rows affected (3.81 sec)Insert some records into the table with the help of insert command −mysql> insert into demo71 values(100, 'John'); Query OK, 1 row affected (0.13 sec) mysql> insert into demo71 values(101, 'David'); Query OK, 1 row affected (0.49 sec) mysql> insert into demo71 values(102, 'Bob'); Query OK, 1 row affected (0.15 sec)Display records from the table using select statement −mysql> select *from ... Read More

What is the difference Between AND, OR operator in MySQL while Retrieving the Rows?

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

2K+ Views

The difference between AND, OR is that AND evaluates both conditions must be true for the overall condition to be true. The OR evaluates one condition must be true for the overall condition to be true.Let us create a table −mysql> create table demo70 −> ( −> id int not null auto_increment primary key, −> name varchar(20), −> age int −> ); Query OK, 0 rows affected (0.67 sec)Insert some records into the table with the help of insert command −mysql> insert into demo70(name, age) values('John', 23); Query OK, 1 row affected (0.18 sec) mysql> insert into demo70(name, age) ... Read More

Update all varchar column rows to display values before slash in MySQL?

AmitDiwan
Updated on 20-Nov-2020 07:29:12

231 Views

For this, use UPDATE command along with SUBSTRING_INDEX(). Let us first create a table −mysql> create table demo69 −> ( −> name varchar(40) −> ); Query OK, 0 rows affected (5.04 sec)Insert some records into the table with the help of insert command −mysql> insert into demo69 values('John/Smith'); Query OK, 1 row affected (0.83 sec) mysql> insert into demo69 values('David/Miller'); Query OK, 1 row affected (0.23 sec) mysql> insert into demo69 values('Chris/Brown'); Query OK, 1 row affected (0.40 sec) mysql> insert into demo69 values('Carol/Taylor'); Query OK, 1 row affected (0.36 sec)Display records from the table using select ... Read More

How to combine few row records in MySQL?

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

126 Views

For this, use CASE WHEN concept. Let us first create a table −mysql> create table demo68 −> ( −> id int not null auto_increment primary key, −> company_name varchar(50), −> employee_name varchar(50), −> country_name varchar(50) −> ); Query OK, 0 rows affected (1.86 sec)Insert some records into the table with the help of insert command −mysql> insert into demo68(company_name, employee_name, country_name) values('Google', 'John', 'US'); Query OK, 1 row affected (0.29 sec) mysql> insert into demo68(company_name, employee_name, country_name) values('Google', 'Bob', 'UK'); Query OK, 1 row affected (0.10 sec) mysql> insert into demo68(company_name, employee_name, country_name) values('Google', 'David', 'AUS'); Query OK, ... Read More

MySQL limit in a range fail to display first 3 row?

AmitDiwan
Updated on 20-Nov-2020 07:25:50

129 Views

Following is the syntax to display only the first 3 rows with LIMIT set in a range −select *from yourTableName limit yourStartIndex, yourEndIndex;Let us first create a table −mysql> create table demo67 −> ( −> id int, −> user_name varchar(40), −> user_country_name varchar(20) −> ); Query OK, 0 rows affected (0.72 sec)Insert some records into the table with the help of insert command −mysql> insert into demo67 values(10, 'John', 'US'); Query OK, 1 row affected (0.19 sec) mysql> insert into demo67 values(1001, 'David', 'AUS'); Query OK, 1 row affected (0.14 sec) mysql> insert into demo67 values(101, 'Mike', 'UK'); ... Read More

MySQL database field type for search query?

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

183 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

How to add a row to a table using only strings from another table as reference in MySQL?

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

214 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

Advertisements