SQLite SELECT articulation is utilized to bring the information from a SQLite data set table which returns information subsequently table. These outcome tables are likewise called result sets.
Syntax
Following is the essential grammar of SQLite SELECT explanation.
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 sentence structure −
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 bring 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.0
In the event that you need to bring 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
In some cases, you will deal with an issue identified with the shortened yield in the event of .mode section which happens on account of default width of the segment to be shown. What you can do is, you can set section 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 principal section width to 10, the second segment width to 20 and the third segment width to 10. At long 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 spot orders are accessible at SQLite brief, henceforth 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 create 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
)