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
In this tutorial, you will learn the use of multi-row suquery in SQLite.
If a subquery returns more than one row they are called as multirow subquery. We cannot handle the multirow subquery result with normal operators.
To handle multirow subquery we need some special operator. SQLite supports IN only as it multi row sub query operator. We know the use of IN operator. IN is used to match more than one value at a time. Same way it works in multi row sub query.
The below query is used to find out each brand low-cost mobile list. So we are just writing a sub query to return minimum price from each brand and comparing the each low price with main query to get each brands low cost mobile.
Select mobile_name,price,brand_name from mobile_sales_details where price in (Select min(price) from mobile_sales_details group by brand_name) mobile_name price brand_name -------------- ---------- ---------- Moto E (Black) 6999 Motorola Asus Zenfone 4 5999 Asus Asus Zenfone 6 16999 Asus Alcatel Onetou 16999 Alcatel Samsung GT 120 1299 Samsung Nokia 105 (Bla 1249 Nokia Apple iPhone 4 21712 Apple Sony Xperia E 6150 Sony Micromax Bolt 882 Micromax Karbonn Smart 2699 Karbonn Lava Arc 12i ( 1210 Lava Lava Iris 406Q 5999 Lava Lenovo A269i ( 3490 Lenovo BlackBerry Cur 9125 BlackBerry