SQLite SELECT proclamation is utilized to get the information from a SQLite data set table which returns information therefore table. These outcome tables are likewise called result sets.
Syntax
Following is the essential language structure of SQLite SELECT proclamation.
SELECT column1, column2, columnN FROM table_name;
Here, column1, column2 ... are the fields of a table, whose qualities you need to get. On the off chance that you need to bring all the fields accessible in the field, at that point you can utilize the accompanying grammar −
SELECT * FROM table_name;
Example
Consider COMPANY table with the accompanying records −
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
Following is a guide to get and show every one of these records utilizing SELECT explanation. Here, the initial three orders have been utilized to set an appropriately designed yield.
sqlite>.header on
sqlite>.mode column
sqlite> SELECT * FROM COMPANY;
At last, you will get the accompanying outcome.
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.
On the off chance that you need to get just chosen fields of COMPANY table, at that point utilize the accompanying question −
sqlite> SELECT ID, NAME, SALARY FROM COMPANY;
The above inquiry will deliver the accompanying outcome.
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
Setting Output Column Width
Now and again, you will deal with an issue identified with the shortened yield if there should be an occurrence of .mode section which happens in light of default width of the segment to be shown. What you can do is, you can set segment displayable segment width utilizing .width num, num.... order as follows −
sqlite>.width 10, 20, 10
sqlite>SELECT * FROM COMPANY;
The abovementioned .width order sets the primary segment width to 10, the second section width to 20 and the third segment width to 10. At last, the above SELECT proclamation will give the accompanying outcome.
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
Schema Information
As all the dab orders are accessible at SQLite brief, subsequently while programming with SQLite, you will utilize the accompanying SELECT assertion with sqlite_master table to list down all the tables made in your information base.
sqlite> SELECT tbl_name FROM sqlite_master WHERE type = 'table';
Accepting you have just COMPANY table in your testDB.db, this will deliver the accompanying outcome.
tbl_name
----------
COMPANY
You can list down total data about COMPANY table as follows −
sqlite> SELECT sql FROM sqlite_master WHERE type = 'table' AND tbl_name = 'COMPANY';
Expecting you have just COMPANY table in your testDB.db, this will create the accompanying outcome.
CREATE TABLE COMPANY(
ID INT PRIMARY KEY NOT NULL,
NAME TEXT NOT NULL,
AGE INT NOT NULL,
ADDRESS CHAR(50),
SALARY REAL
)