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
Between And:
Between ... and ... operator is used to get range of values. Say for example, if you want to know mobile list which falls in the price range between 5000 and 10000, use the below query
Select mobile_name,type,price from mobile_sales_details where price between 5000 and 10000
mobile_name type price
-------------- ---------- ----------
Moto E (Black) Smartphone 6999
Asus Zenfone 4 Smartphone 5999
Asus Zenfone 5 Smartphone 9999
Samsung Galaxy Smartphone 8206
Samsung Galaxy Smartphone 7599
Samsung Galaxy Smartphone 8214
Samsung Galaxy Smartphone 9610
Nokia Lumia 63 Smartphone 9479
Sony Xperia E Smartphone 6150
Micromax Canva Smartphone 8340
Micromax Canva Smartphone 9074
Micromax Unite Smartphone 8499
Micromax Canva Smartphone 8590
IN
In SQL you cannot match more than one value at a time. To solve this, we have IN operator. IN operator is used to get more than one exact match in single query.
The below query is used to get mobile list of Samsung and Sony brand
Select mobile_name,price,brand_name from mobile_sales_details where brand_name in (’Samsung’,’Sony’)
mobile_name price brand_name
------------------------------------------ ---------- ----------
Samsung Galaxy S Duos 2 S7582 (Pure White) 8206 Samsung
Samsung Galaxy Star Pro S7262 (White) 7599 Samsung
Samsung Galaxy S Duos 2 S7582 (Black) 8214 Samsung
Samsung Galaxy Core I8262 (Chic White) 11795 Samsung
Samsung Galaxy Grand 2 (Black) 18990 Samsung
Samsung Galaxy Trend S7392 (Midnight Black 9610 Samsung
Samsung Galaxy Grand Neo GT-I9060 (White) 14010 Samsung
Samsung I8552 - Galaxy Grand Quattro 15999 Samsung
Samsung Galaxy S4 Mini I9192 (White Frost) 24730 Samsung
Samsung GT 1200 R/I/M 1299 Samsung
Samsung Guru 1200 (Black) 1399 Samsung
Samsung Galaxy S5 (Charcoal Black) 54300 Samsung
Samsung Galaxy S4 I9500 (White Frost) 28071 Samsung
Samsung Guru E1207T (Black) 1450 Samsung
Samsung Galaxy S3 (Marble White with 16GB 31850 Samsung
IS NULL:
NULL is value. Its not blank, space, or zero. It is a value like other literals.
If you want to know list of mobiles which have no discount, we can use the IS NULL keyword
Select mobile_name ,price ,brand_name,discount from mobile_sales_details where discount is null
mobile_name price brand_name discount
---------------------- ---------- ---------- ----------
Moto X (16 GB) (Black) 23999 Motorola
Moto G (Black with 16 13999 Motorola
Moto E (Black) 6999 Motorola
Asus Zenfone 4 A400CG 5999 Asus
Asus Zenfone 5 A501CG 9999 Asus
Asus Zenfone 5 A501CG 12999 Asus
Asus Zenfone 6 A600CG 16999 Asus
Alcatel Onetouch Idol 16999 Alcatel
Samsung Galaxy S Duos 8206 Samsung
Samsung Galaxy S Duos 8214 Samsung
Samsung Galaxy Core I8 11795 Samsung
Samsung Galaxy Grand 2 18990 Samsung
Samsung Galaxy Grand N 14010 Samsung
Samsung I8552 - Galaxy 15999 Samsung
Samsung Galaxy S4 I950 28071 Samsung
Nokia Lumia 630 Dual S 9479 Nokia
Nokia Lumia 1320 (Blac 17190 Nokia