0% found this document useful (0 votes)
30 views

What Is SQL Query?

A query is a request for data or information from a database table. A nested query, also called a subquery, is a query within another SQL query that is embedded in the WHERE clause. A nested query returns data that is used as a condition to further restrict the results of the main query. Query optimization is the process of rewriting queries or determining the most efficient execution plan to improve performance. The query optimizer considers different query plans and algorithms to select the most optimal way to execute a given query.

Uploaded by

salina khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

What Is SQL Query?

A query is a request for data or information from a database table. A nested query, also called a subquery, is a query within another SQL query that is embedded in the WHERE clause. A nested query returns data that is used as a condition to further restrict the results of the main query. Query optimization is the process of rewriting queries or determining the most efficient execution plan to improve performance. The query optimizer considers different query plans and algorithms to select the most optimal way to execute a given query.

Uploaded by

salina khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 2

what is SQL Query?

A query is a request for data or information from a database table or combination of tables. This
data may be generated as results returned by Structured Query Language (SQL) or as pictorials,
graphs or complex results, e.g., trend analyses from data-mining tools.

What Is Nested Query?

A Subquery or Inner query or a Nested query is a query within another SQL query and
embedded within the WHERE clause. A subquery is used to return data that will be used in the main
query as a condition to further restrict the data to be retrieved.
Subqueries can be used with the SELECT, INSERT, UPDATE, and DELETE statements along with
the operators like =, <, >, >=, <=, IN, BETWEEN, etc.
Subqueries with the SELECT Statement

SELECT column_name [, column_name ]


FROM table1 [, table2 ]
WHERE column_name OPERATOR
(SELECT column_name [, column_name ]
FROM table1 [, table2 ]
[WHERE])
OR

SELECT job_id,AVG(salary)
FROM employees
GROUP BY job_id
HAVING AVG(salary)<
(SELECT MAX(AVG(min_salary))
FROM jobs
WHERE job_id IN
(SELECT job_id FROM job_history
WHERE department_id
BETWEEN 50 AND 100)
GROUP BY job_id);

Simple Queries:
Selecting all records from a table and displaying all columns:

SELECT * FROM EMPLOYEE_TBL;

Selecting all records from a table and displaying a specified column:

SELECT EMP_ID
FROM EMPLOYEE_TBL;

Complex query:
AND Query

It might be an AND query. The example below shows that the query is searching for event =
birthday AND paid = yes

OR Query

It might be searching using two parameters for event = lunch OR event = birthday

NOT Query

The parameters might be looking for all events except for birthday.

What is a recursive SQL?

A recursive query is one that refers to itself.

Query Optimization:
A single query can be executed through different algorithms or re-written in different forms and
structures. Hence, the question of query optimization comes into the picture – Which of these forms
or pathways is the most optimal? The query optimizer attempts to determine the most efficient way
to execute a given query by considering the possible query plans.

Query optimization is a function of many relational database management systems. The query
optimizer attempts to determine the most efficient way to execute a given query by considering the
possible query plans.

You might also like