SQLite - SPLessons
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

SQLite Queries

SQLite Queries

shape Description

SQLite Queries are nested queries where the result of one query can be used in another query via relational operator or aggregation functions. And SQLite Queries must be enclosed within parentheses and contains only one column in the select clause if used in where clause. An orderby clause is not allowed in a SQLite Queries. And this can be nested within other SQLite Queries. SQLite Queries are used in where, having, from and in select clauses. SQLite subqueries are used to extract data from the database in a readable format according to the request given by the user.And SQLite Queries is a query inside another SQLite query and implanted inside the where clause.And a subquery is a SQL query nested within a larger query.A subquery can be considered as an internal query,which is a SQL query set  as a part of another query called as external queries. And a SQLite subqueries may happens in: A subquery is typically included inside the where condition of another SQL select proclamation.And these subqueries will utilize the comparison operators like =,> or <.These comparison operator can also be a multiple-row operator such as NOT IN ,IN.During the process of subqueries,the internal query will be executed first and passes these internal query to external query.

Types of subquries

shape Description

The subqueries can be classified into the following types.

shape Syntax

Select select_list from table where expr operator.
The internal query will be executed first and the output of these internal query will be used by the external query.

shape Examples

By viewing the below example,the concept of subqueries can be easily understand [c] sqlite> create table employees(Emp_id int,First_Name varchar2(20),Last_Name varchar2(20),Email varchar2(20),Mobile number int,Salary int); sqlite> insert into employees values(1001,'John','David','David@gmail.com',9701662524,25000); sqlite> insert into employees values(1002,'Mike','Tyson','Tyson@gmail.com',9701624265,25200); sqlite> insert into employees values(1003,'David','Warner','Warner@gmail.com',9701657261,26000); sqlite> insert into employees values(1004,'Malik','Winner','Winner@gmail.com',9725254485,26000); sqlite> insert into employees values(1005,'Jack','Wolfner','Wolfner@gmail.com',9441203170,26000); sqlite> select * from employees; 1001|John|David|David@gmail.com|9701662524|25000 1002|Mike|Tyson|Tyson@gmail.com|9701624265|25200 1003|David|Warner|Warner@gmail.com|9701657261|26000 1004|Malik|Winner|Winner@gmail.com|9725254485|26000 1005|Jack|Wolfner|Wolfner@gmail.com|9441203170|26000 sqlite> select First_Name,Last_Name,salary from employees where salary>(select salary from employees where Last_Name='David'); Mike|Tyson|25200 David|Warner|26000 Malik|Winner|26000 Jack|Wolfner|26000 [/c] In the above example a query with in an subquery has been as been evaluated,in which the subquery will be executed first and the output of the subquery will be given as input to main query.

Summary

shape Points

  • Subqueries - A query within the query is said to be sub query.
  • Query - Is nothing but a statement.