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

LIMIT the Rows Retrieved by Query Basic select statement is used to retrieve all the records from the table. However, many times we need to filter the record by specifying some conditions.

To write condition here we have WHERE clause. WHERE takes Boolean result as its input, if the result is true, it will return the result table or else it will not return anything.

Syntax for where clause:


SELECT *|{[DISTINCT] column|expression [alias],…}
FROM table
[WHERE condition(s)];

We have to write WHERE clause after the table Say for example, if you want to know how many mobiles have 5 mega pixel camera, the query is as follows


Select mobile_name from mobile_sales_details where primary_camera_pixel=5

mobile_name               
--------------------------
Moto G (Black  with 16 GB)
Moto E (Black)            
Asus Zenfone 4 A400CG (Bla
Samsung Galaxy S Duos 2 S7
Samsung Galaxy S Duos 2 S7
Samsung Galaxy Core I8262 
Samsung Galaxy Grand Neo G
Samsung I8552 - Galaxy Gra
Nokia Lumia 520 (Black)   
Nokia Lumia 630 Dual SIM (
Nokia XL (Bright Orange)  
Nokia Lumia 1320 (Black)  
Nokia Lumia 625 (Black)

Here the = (equal) operator is used to get the list of mobiles, whose primary camera pixel size is 5. Here the value(5) is number so we can directly use it.

However, if want to compare text and date value, you must place them inside the single quote. If you want to know, how many Samsung mobile are available. Brand_name column hold the different type of brands.


Select mobile_name from mobile_sales_details where brand_name=’Samsung’

mobile_name                               
------------------------------------------
Samsung Galaxy S Duos 2 S7582 (Pure White)
Samsung Galaxy Star Pro S7262 (White)     
Samsung Galaxy S Duos 2 S7582 (Black)     
Samsung Galaxy Core I8262 (Chic White)    
Samsung Galaxy Grand 2 (Black)            
Samsung Galaxy Trend S7392 (Midnight Black
Samsung Galaxy Grand Neo GT-I9060 (White) 
Samsung I8552 - Galaxy Grand Quattro      
Samsung Galaxy S4 Mini I9192 (White Frost)
Samsung GT 1200 R/I/M                     
Samsung Guru 1200 (Black)                 
Samsung Galaxy S5 (Charcoal Black)        
Samsung Galaxy S4 I9500 (White Frost)     
Samsung Guru E1207T (Black)               
Samsung Galaxy S3 (Marble White  with 16GB

The above result displays the available mobile list under Samsung brand.

Samsung is a text so it was placed inside the single quote(‘ ‘) If you want to know smartphone list and their price


Select mobile_name,price from mobile_sales_details where type=’Smartphone’

mobile_name             price     
----------------------  ----------
Moto X (16 GB) (Black)  23999     
Moto G (Black  with 16  13999     
Moto E (Black)          6999      
Asus Zenfone 4 A400CG   5999      
Asus Zenfone 5 A501CG   9999      
Asus Zenfone 5 A501CG   12999     
Asus Zenfone 6 A600CG   16999     
Alcatel Onetouch Idol   16999     
Samsung Galaxy S Duos   8206      
Samsung Galaxy Star Pr  7599      
Samsung Galaxy S Duos   8214

If you want to have a list of single SIM type mobile


Select mobile_name, price from mobile_sales_details where sim_type=’Single’

mobile_name             price     
----------------------  ----------
Moto X (16 GB) (Black)  23999     
Samsung GT 1200 R/I/M   1299      
Samsung Guru 1200 (Bla  1399      
Samsung Galaxy S5 (Cha  54300     
Samsung Galaxy S4 I950  28071     
Samsung Galaxy S3 (Mar  31850     
Nokia Lumia 520 (Black  11289     
Nokia 105 (Black)       1249      
Nokia Lumia 1320 (Blac  17190     
Nokia Lumia 625 (Black  16500     
Apple iPhone 5S (Gold   43199