Found 6702 Articles for Database

Group result in MySQL and show on list?

AmitDiwan
Updated on 19-Nov-2020 10:58:57

77 Views

For this, use GROUP BY along with ORDER BY −select yourColumnName, count(*) as anyAliasName from yourTableName group by yourColumnName order by yourColumnName;Let us create a table −mysql> create table demo7 −> ( −> id int NOT NULL AUTO_INCREMENT, −> first_name varchar(50) −> , −> primary key(id) −> ); Query OK, 0 rows affected (1.22 sec)Insert some records into the table with the help of insert command −mysql> insert into demo7(first_name) values('John'); Query OK, 1 row affected (0.09 sec) mysql> insert into demo7(first_name) values('David'); Query OK, 1 row affected (0.22 sec) mysql> insert into demo7(first_name) values('John'); Query OK, 1 row affected ... Read More

MySQL Error ERROR 1099 (HY000): Table was locked with a READ lock and can't be updated

AmitDiwan
Updated on 19-Nov-2020 10:54:59

555 Views

To get rid of LOCK TABLES query, you need to use UNLOCK TABLES.Let us create a table −mysql> create table demo6 −> ( −> country_name varchar(100 −> ) −> ); Query OK, 0 rows affected (1.51 sec)Insert some records into the table with the help of insert command −mysql> insert into demo6 values('US'); Query OK, 1 row affected (0.11 sec) mysql> insert into demo6 values('UK'); Query OK, 1 row affected (0.08 sec) mysql> insert into demo6 values('AUS'); Query OK, 1 row affected (0.11 sec)Display records from the table using select statement −mysql> select *from demo6;This will produce the ... Read More

Limit total number of results across tables in MySQL?

AmitDiwan
Updated on 19-Nov-2020 10:48:20

92 Views

For this, you can use UNION ALL along with LIMIT concept. For our example, we will create three tables.Let us create the first table −mysql> create table demo3 −> ( −> value int −> ); Query OK, 0 rows affected (1.39 sec)Insert some records into the table with the help of insert command −mysql> insert into demo3 values(10); Query OK, 1 row affected (0.13 sec) mysql> insert into demo3 values(20); Query OK, 1 row affected (0.08 sec) mysql> insert into demo3 values(30); Query OK, 1 row affected (0.08 sec)Display records from the table using select statement −mysql> select ... Read More

Multiple LIKE Operators with ORDER BY in MySQL?

AmitDiwan
Updated on 19-Nov-2020 10:40:51

159 Views

Following is the syntax implementing multiple LIKE operators with ORDER BY −select *from yourTableName order by (    yourColumnName like '%yourValue1%' ) + (    yourColumnName like '%yourValue2%' ) + . . N desc;Let us create a table −mysql> create table demo2 −> ( −> id int not null auto_increment, −> name varchar(100), −> primary key(id) −> ); Query OK, 0 rows affected (1.53 sec)Insert some records into the table with the help of insert command −mysql> insert into demo2(name) values('John'); Query OK, 1 row affected (0.18 sec) mysql> insert into demo2(name) values('David'); Query OK, 1 row affected (0.09 ... Read More

How to get number located at 2 places before decimal point MySQL?

AmitDiwan
Updated on 19-Nov-2020 10:37:16

160 Views

In order to get number located at 2 places before decimal point, you can use the concept of div.Let us create a table −mysql> create table demo1 −> ( −> value float −> ); Query OK, 0 rows affected (2.20 sec)Insert some records into the table with the help of insert command −mysql> insert into demo1 values(456.54); Query OK, 1 row affected (0.16 sec) mysql> insert into demo1 values(50.64); Query OK, 1 row affected (0.17 sec) mysql> insert into demo1 values(1000.78); Query OK, 1 row affected (0.13 sec)Display records from the table using select statement −mysql> select *from demo1;This will ... Read More

What is the usage of scrollable cursor for current positioning?

Mandalika
Updated on 15-Sep-2020 11:14:12

143 Views

We can use SCROLLABLE CURSOR to directly point the cursor to the mentioned relative position. The relative position is the position of the row in the result table from the current row. For example, consider the table below.ORDER_IDORDER_DATEA223672020-07-28A667562020-07-28A778902020-07-29A968322020-07-29If the cursor is currently pointing to the 2nd absolute row i.e, ORDER_ID A66756 then the relative +2 position will be ORDER_ID A96832 and relative -1 position will be ORDER_ID A22367.The syntax to use relative position in FETCH statement is−EXEC SQL    FETCH RELATIVE +2 ORDER_CURR    INTO :ORDER-ID, :ORDER-DATE END-SQLRead More

What is the usage of scrollable cursor for absolute positioning?

Mandalika
Updated on 15-Sep-2020 11:12:39

274 Views

The SCROLLABLE CURSOR can be used to directly point the cursor position to the mentioned absolute position. The absolute position is the position of a particular row in the result table from the first row.We can fetch the absolute position by using ABSOLUTE parameter in the FETCH statement. For example, we have to declare a scrollable cursor as below.EXEC SQL       DECLARE ORDER_CURR SCROLL CURSOR FOR          SELECT ORDER_ID, ORDER_DATE FROM ORDERS             WHERE ORDER_DATE = ‘2020-07-29’ END-SQLNow if we want to fetch the absolute 9th row then we will ... Read More

What is the difference between SENSITIVE and INSENSITIVE scrollable CURSOR with syntax

Mandalika
Updated on 15-Sep-2020 11:10:15

1K+ Views

The INSENSITIVE SCROLLABLE CURSOR are sort of read only cursors in which the result table cannot change once the cursor is opened. The other applications also cannot update the INSENSITIVE SCROLLABLE CURSOR once it is opened. The SENSITIVE SCROLLABLE CURSOR, unlike INSENSITIVE are sensitive to changes made in the result table. The changes made by other applications will be reflected in the result table.We can declare SENSITIVE and INSENSITIVE SCROLLABLE CURSOR like below.EXEC SQL       DECLARE ORDER_CURR SENSITIVE SCROLL CURSOR FOR          SELECT ORDER_ID, ORDER_DATE FROM ORDERS             WHERE ORDER_DATE ... Read More

Write the syntax to declare a scrollable cursor on the ORDERS DB2 table.

Mandalika
Updated on 15-Sep-2020 11:08:13

439 Views

A SCROLLABLE CURSOR can move in both forward and backward direction. In other words, it can fetch next as well as previous rows. A SCROLLABLE CURSOR is declared using the “SCROLL” clause in the DECLARE CURSOR.For example, if we want to declare a SCROLLABLE CURSOR on the ORDERS table then we have to declare the cursor like below.EXEC SQL       DECLARE ORDER_CURR SCROLL CURSOR FOR          SELECT ORDER_ID, ORDER_DATE FROM ORDERS             WHERE ORDER_DATE = ‘2020-07-29’ END-SQL

What is the purpose and usage of SCROLLABLE CURSOR in COBOLDB2 program?

Mandalika
Updated on 15-Sep-2020 11:06:45

365 Views

A cursor can move only in forward direction, which means that it can extract the next row after every fetch. It is not possible to extract the previous row using a cursor.For example, if our resultant cursor contains following rows−ORDER_IDORDER_DATEA223672020-07-28A667562020-07-28A778902020-07-29A968322020-07-29If our cursor is currently pointing to 3rd row i.e. order id A77890 then the next fetch will point the cursor to the next row i.e. order id A96832. It is not possible to point the cursor to the previous order id i.e. A66756.In order to achieve this, we use the concept of SCROLLABLE CURSOR. The SCROLLABLE CURSOR can move both ... Read More

Advertisements