- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 6702 Articles for Database
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
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
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
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
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
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
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
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
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
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
![Mandalika](https://www.tutorialspoint.com/assets/profiles/223769/profile/60_143952-1595686763.jpg)
144 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
![Mandalika](https://www.tutorialspoint.com/assets/profiles/223769/profile/60_143952-1595686763.jpg)
275 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
![Mandalika](https://www.tutorialspoint.com/assets/profiles/223769/profile/60_143952-1595686763.jpg)
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
![Mandalika](https://www.tutorialspoint.com/assets/profiles/223769/profile/60_143952-1595686763.jpg)
440 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
![Mandalika](https://www.tutorialspoint.com/assets/profiles/223769/profile/60_143952-1595686763.jpg)
366 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