sqlite

Database; use; embedded relational database

select

英[s??lekt] 美[s??l?kt ]

vt.choose;select;select

adj.selected;chosen;choose;

SQLite Select function syntax

Function:SQLite's SELECT statement is used to obtain data from the SQLite database table and return the data in the form of a result table. These result tables are also called result sets.

Syntax: SELECT column1, column2, columnN FROM table_name; Here, column1, column2... are the fields of the table, and their values ??are what you want to get. If you want to get all available fields, you can use the following syntax: SELECT * FROM table_name;

SQLite Select function example

COMPANY 表有以下記錄:

ID          NAME        AGE         ADDRESS     SALARY
----------  ----------  ----------  ----------  ----------
1           Paul        32          California  20000.0
2           Allen       25          Texas       15000.0
3           Teddy       23          Norway      20000.0
4           Mark        25          Rich-Mond   65000.0
5           David       27          Texas       85000.0
6           Kim         22          South-Hall  45000.0
7           James       24          Houston     10000.0
用 SELECT 語句獲取并顯示所有這些記錄。在這里,前三個命令被用來設置正確格式化的輸出。

sqlite>.header on
sqlite>.mode column
sqlite> SELECT * FROM COMPANY;
最后,將得到以下的結果:

ID          NAME        AGE         ADDRESS     SALARY
----------  ----------  ----------  ----------  ----------
1           Paul        32          California  20000.0
2           Allen       25          Texas       15000.0
3           Teddy       23          Norway      20000.0
4           Mark        25          Rich-Mond   65000.0
5           David       27          Texas       85000.0
6           Kim         22          South-Hall  45000.0
7           James       24          Houston     10000.0
如果只想獲取 COMPANY 表中指定的字段,則使用下面的查詢:

sqlite> SELECT ID, NAME, SALARY FROM COMPANY;
上面的查詢會產生以下結果:

ID          NAME        SALARY
----------  ----------  ----------
1           Paul        20000.0
2           Allen       15000.0
3           Teddy       20000.0
4           Mark        65000.0
5           David       85000.0
6           Kim         45000.0
7           James       10000.0