×

MySQL Descending Index

Descending Index

It is a type of index that stores key values in descending order. This query improves the performance of an index query. MySQL system displays the index as per column order in the table.

Suppose you want to display the index in order as per your requirement. The index order assigns either ascending or descending. You will use the "DESC" keyword for descending order. If you want your index in ascending order, then use the "ASC" keyword.

Syntax

The basic syntax of the descending index shows below.

INDEX key_name (column1 DESC, column DESC)

MySQL descending index shows below.

 CREATE TABLE table_name
 (Column1 INT NOT NULL,
 Column INT NOT NULL,
 INDEX key_name (column1 DESC, column DESC));
 MySQL ascending index shows below.
 CREATE TABLE table_name
 (Column1 INT NOT NULL,
 Column INT NOT NULL,
 INDEX key_name (column1 ASC, column ASC));
 MySQL descending and ascending index shows below.
 CREATE TABLE table_name
 (Column1 INT NOT NULL,
 Column INT NOT NULL,
 INDEX key_name (column1 DESC, column ASC)); 

Examples of the Descending index

1) Example: The basic descending index example shows below.

Execute the below query to get descending orders of the column. Here we will assign the DESC keyword to the phone and name column.

 mysql> create table index_table(
 roll_number INT NOT NULL PRIMARY KEY,
 phone INT NOT NULL,
 name VARCHAR(10) NOT NULL,
 mark text NOT NULL,
 img blob NOT NULL,
 INDEX roll_number (phone DESC),
 INDEX name (name DESC),
 INDEX img (img (400) DESC)); 

OUTPUT

Execute the below query to get the required index and its information.

mysql> show index from index_table;
Descending Index

The above output image shows a similar index name for multiple columns. The collation shows the "D" value, which means descending order for the index.

2) Example: The multiple descending index example shows below.

Execute the below query to get descending orders of the column. All column uses descending order using the "DESC" keyword. The multiple indexes with several columns assign for descending index.

 mysql> create table index_table(
 roll_number INT NOT NULL PRIMARY KEY,
 phone INT NOT NULL,
 name VARCHAR(10) NOT NULL,
 mark text NOT NULL,
 img blob NOT NULL,
 INDEX roll_number (roll_number DESC, phone DESC),
 INDEX name (name DESC, mark (100) DESC),
 INDEX img (img (400) DESC)); 

OUTPUT

Execute the below query to get the required index and its information.

mysql> show index from index_table;
Descending Index

The above output image shows a single index name for multiple columns. The collation shows the "D" value, which means descending order for the index.

3) Example: The basic ascending index example shows below.

Execute the below query to get descending orders of the column. All column uses order with the "ASC" and "DESC" keyword. The multiple indexes with several table columns assign for ascending and descending index.

 mysql> create table index_table(
 roll_number INT NOT NULL PRIMARY KEY,
 phone INT NOT NULL,
 name VARCHAR(10) NOT NULL,
 mark text NOT NULL,
 img blob NOT NULL,
 INDEX roll_number (roll_number DESC, phone ASC),
 INDEX name (name DESC, mark(10) DESC),
 INDEX img (img(100) ASC)); 

OUTPUT

Execute the below query to get the required index and its information.

mysql> show index from index_table;
Descending Index

The above output image shows a single index name to multiple columns. The collation shows the "A" and "D" values where "A" displays an ascending order and "D" displays a descending order to the index. The complete table index assigns descending order.

4) Example: The descending and ascending index example shows below.

Execute the below query to get ascending orders of the column. All column uses ascending order using the "ASC" keyword. The multiple indexes with several table columns assign to ascending index.

 mysql> create table index_table(
 roll_number INT NOT NULL PRIMARY KEY,
 phone INT NOT NULL,
 name VARCHAR(10) NOT NULL,
 mark text NOT NULL,
 img blob NOT NULL,
 INDEX roll_number (roll_number ASC, phone ASC),
 INDEX name (name ASC, mark(10) ASC),
 INDEX img (img(100) ASC)); 

OUTPUT

Execute the below query to get the required index and its information.

mysql> show index from index_table;
Descending Index

The above output image shows a single index name for multiple columns. The collation shows the "A" value, which means ascending order for index. The complete table index assigns ascending order.


Related Topics

MySQL String Function

The string function is used to maintain and operate string values. This function modifies the string data as per function. We can do the concatenation, conversion, removal and replacing the...

4 minutes read.

MySQL LOG10() function

In this context, we will learn how we can use the MySQL LOG10() function with proper syntax and good examples. Introduction of MySQL LOG10() function To evaluate the natural logarithmic value of...

2 minutes read.

MySQL Queries

MySQL Queries MySQL supports SQL queries in the MySQL interface. These queries help to interact data with the application. MySQL uses create database, user database, create a table, truncate table, and...

13 minutes read.

MySQL FORMAT() function

In this context, we will learn how we can use the MySQL FORMAT() function with proper syntax and good examples. Introduction of MySQL FORMAT() function This function in MySQL helps to format...

2 minutes read.

MySQL Advance table Query

MySQL Advance table Query The table is created by index, rows, and columns in the MySQL database. The user saves their information in matrix format. The database requires a query to...

14 minutes read.

MySQL Constraints

MySQL Constraints Introduction The constraints help to restrict what values should be stored in a table. The constraints provide limitations of the columns or data. This function helps to insert data in...

20 minutes read.

MySQL LEAST function

This statement displays the smallest value of the table. The LEAST function returns a null value when the table contains a null value. If the table contains all numerical values,...

2 minutes read.

MySQL POWER() function

In this context, we will learn how we can use the MySQL POWER() function with proper syntax and good examples. Introduction of MySQL POWER() function The value of a number raised to...

3 minutes read.

MySQL Data Types

Introduction of the Data types In the data file, we have several information such as names, numbers, marks, and other information. This information specifies categories such as numbers, characters, and decimal...

8 minutes read.

MySQL SOUNDEX() function

In this context, we will learn how we can use the MySQL SOUNDEX() function with proper syntax and good examples. Introduction of MySQL SOUNDEX() function SOUNDEX() function in MySQL is used to...

3 minutes read.

MySQL Descending Index

Descending Index It is a type of index that stores key values in descending order. This query improves the performance of an index query. MySQL system displays the index as per...

3 minutes read.

MySQL Composite Index

Composite Index A composite index is an index that is used on multiple columns. MySQL management system manages multiple columns simultaneously. Therefore, the single index contains multiple columns in one query...

3 minutes read.

MySQL INSTR() Function

In this context, we will learn how we can use the MySQL INSTR() function with proper syntax and good examples. Introduction of MySQL INSTR() function This function in MySQL returns the location...

4 minutes read.

MySQL Prefix index

Prefix index This index query creates an index column in the string or character column. MySQL system can create multiple indexes in the table. It will create in a table as...

3 minutes read.

MySQL POW() function

In this context, we will learn how we can use the MySQL POW() function with proper syntax and good examples. Introduction of MySQL POW() function This function in MySQL is used to...

2 minutes read.

MySQL MOD() function

In this context, we will learn how we can use the MySQL MOD() function with proper syntax and good examples. Introduction of MySQL MOD() function Basically, in MySQL, the MOD() function is...

3 minutes read.

MySQL TAN() Function

Basically, the TAN() function in MySQL is used to give back the tangent of a mentioned number.In any kind of right-angle triangle, the tangent of an angle is the length...

2 minutes read.

MySQL Index

An index is a widely used method to access table information quickly. MySQL requires an index for operating table data stored in rows and columns. It's an entry point of...

3 minutes read.

MySQL DATE_FORMAT() function

In this context, we will learn how we can use the MySQL DATE_FORMAT() function with proper syntax and good examples. Introduction of MySQL DATE_FORMAT() function DATE_FORMAT() function in MySQL is used to...

3 minutes read.

MySQL FROM_BASE64() function

In this context, we will learn how we can use the MySQL FROM_BASE64()() function with proper syntax and good examples. Introduction of MySQL FROM_BASE64()() function Basically, the FROM_BASE64() function In MySQL decodes...

2 minutes read.