English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

SQLite Subquery Indexes

‘INDEXED BY index-name clause specifies that a named index must be used to find values in the above table.

If index-If the name does not exist or cannot be used in the query, the preparation of the SQLite statement fails.

The 'NOT INDEXED' clause specifies that an index is not used when accessing the above table, including implicit indexes created by UNIQUE and PRIMARY KEY constraints.

However, even if 'NOT INDEXED' is specified, entries can still be found using INTEGER PRIMARY KEY.

Syntax

The following is the syntax of the INDEXED BY clause, which can be used with DELETE, UPDATE, or SELECT statements.

SELECT|DELETE|UPDATE column1, column2...INDEXED BY (index_name) table_name WHERE (CONDITION);

Online Examples

In the table COMPANY, we will create an index and use it for the INDEXED BY operation.

sqlite> CREATE INDEX salary_index ON COMPANY(salary);
sqlite>

Now select data from the table COMPANY, you can use the INDEXED BY clause as follows:

sqlite> SELECT * FROM COMPANY INDEXED BY salary_index WHERE salary > 5000;

This will produce the following result.

ID          NAME        AGE         ADDRESS     SALARY
----------  ----------  ----------  ----------  ----------
7           James       24          Houston     10000.0
2           Allen       25          Texas       15000.0
1           Paul        32          California  20000.0
3           Teddy       23          Norway      20000.0
6           Kim         22          South-Hall  45000.0
4           Mark        25          Rich-Mond   65000.0
5           David       27          Texas       85000.0