General Note:

Here we have pulled in the data from a sample database. You can download it from the following link and use it for practicing Click Here For Sample Database

.tables is SQLite command to show available tables in database

 
brand_details         country_codes         mobile_sales_details
company_location      mobile_rating         test 

SELECT keyword is used to retrieve data from one or more tables. Main purpose of the SELECT keyword is data retrieval.

Select keyword does not change any data which is present in the table. It is used to display data from the tables as per the the query (statement).

Basic SELECT Syntax

 
SELECT *|{[DISTINCT] column|expression [alias],...}
FROM table;

[ ] - optional field | either this or that but not both * - select all column in table(s) If you want to select all column in table, use the below query.

We have mobile_rating table, which holds records such as mobile name and ratings in star.

If you have to select all columns and records from the mobile_rating table, the query is

 
Select * from mobile_rating
 
mobile_name             star5       star4       star3       star2       star1     
----------------------  ----------  ----------  ----------  ----------  ----------
Moto X (16 GB) (Black)  20072       6544        1160        460         1357      
Moto G (Black  with 16  2078        683         151         76          200       
Moto E (Black)          12900       5057        1088        394         989       
Asus Zenfone 4 A400CG   195         91          26          8           34        
Asus Zenfone 5 A501CG   465         196         38          16          71        
Asus Zenfone 5 A501CG   114         60          17          8           14        
Asus Zenfone 6 A600CG   74          27          9           5           13        
Alcatel Onetouch Idol   368         150         42          20          47        
Samsung Galaxy S Duos   981         691         193         97          185       
Samsung Galaxy Star Pr  348         330         154         56          102       
Samsung Galaxy S Duos   981         691         193         97          185       
Samsung Galaxy Core I8  516         413         167         52          147       
Samsung Galaxy Grand 2  393         193         56          46          132       
Samsung Galaxy Trend S  128         104         50          39          185       
Samsung Galaxy Grand N  38          21          8           6           100       
Samsung I8552 - Galaxy  574         394         93          54          166

If you want to select only mobile name from table

 
Select mobile_name from mobile_rating
 
mobile_name           
----------------------
Moto X (16 GB) (Black)
Moto G (Black  with 16
Moto E (Black)        
Asus Zenfone 4 A400CG 
Asus Zenfone 5 A501CG 
Asus Zenfone 5 A501CG 
Asus Zenfone 6 A600CG 
Alcatel Onetouch Idol 
Samsung Galaxy S Duos 
Samsung Galaxy Star Pr
Samsung Galaxy S Duos 
Samsung Galaxy Core I8
Samsung Galaxy Grand 2
Samsung Galaxy Trend S
Samsung Galaxy Grand N
Samsung I8552 - Galaxy

It will display all the rows available in the mobile_rating table. Use the correct column name or else it will throw an error.

If you want to select more than one column from table use comma (,) between the columns

 
Select mobile_name, star5 from mobile_rating
 
mobile_name             star5     
----------------------  ----------
Moto X (16 GB) (Black)  20072     
Moto G (Black  with 16  2078      
Moto E (Black)          12900     
Asus Zenfone 4 A400CG   195       
Asus Zenfone 5 A501CG   465       
Asus Zenfone 5 A501CG   114       
Asus Zenfone 6 A600CG   74        
Alcatel Onetouch Idol   368       
Samsung Galaxy S Duos   981       
Samsung Galaxy Star Pr  348       
Samsung Galaxy S Duos   981       
Samsung Galaxy Core I8  516       
Samsung Galaxy Grand 2  393       
Samsung Galaxy Trend S  128       
Samsung Galaxy Grand N  38        
Samsung I8552 - Galaxy  574       
Samsung Galaxy S4 Mini  216

Here we are going to select four columns from table using comma

 
Select mobile_name, type, price, discount from mobile_sales_details
 
mobile_name             type        price       discount  
----------------------  ----------  ----------  ----------
Moto X (16 GB) (Black)  Smartphone  23999                 
Moto G (Black  with 16  Smartphone  13999                 
Moto E (Black)          Smartphone  6999                  
Asus Zenfone 4 A400CG   Smartphone  5999                  
Asus Zenfone 5 A501CG   Smartphone  9999                  
Asus Zenfone 5 A501CG   Smartphone  12999                 
Asus Zenfone 6 A600CG   Smartphone  16999                 
Alcatel Onetouch Idol   Smartphone  16999                 
Samsung Galaxy S Duos   Smartphone  8206                  
Samsung Galaxy Star Pr  Smartphone  7599        23        
Samsung Galaxy S Duos   Smartphone  8214                  
Samsung Galaxy Core I8  Smartphone  11795                 
Samsung Galaxy Grand 2  Smartphone  18990                 
Samsung Galaxy Trend S  Smartphone  9610        28        
Samsung Galaxy Grand N  Smartphone  14010                 
Samsung I8552 - Galaxy  Smartphone  15999                 
Samsung Galaxy S4 Mini  Smartphone  24730       26        
Samsung GT 1200 R/I/M   Ordinary    1299        17        
Samsung Guru 1200 (Bla  Ordinary    1399        9         
Samsung Galaxy S5 (Cha  Smartphone  54300       30