SQLite Select function


  Translation results:

sqlite

Database; use; embedded relational database

select

英[sɪˈlekt] 美[sɪˈlɛkt ]

vt.choose;select;select

adj.selected;chosen;choose;

SQLite Select functionsyntax

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 functionexample

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

Popular Recommendations

Home

Videos

Q&A