What is sub-query? Explain properties of sub-query?

Asked 20-Nov-2017
Updated 28-Mar-2024
Viewed 689 times

1 Answer


0

Overview:

A subquery, also known as a nested query or inner query, is a query nested within another SQL statement, such as SELECT, INSERT, UPDATE, or DELETE. It is utilized to recover insights from one or additional tables basically founded on one-of-a-kind principles, and its belongings are utilized as a condition or articulation inside the external question. Subqueries can be extremely flexible and are normally utilized in SQL questions to get out, make due, or recover measurements in a more granular and dynamic manner.

What is subquery Explain properties of subquery

Properties of subqueries envelop:

1. Epitome: Subqueries are encased inside brackets and managed as an unmarried unit inside the essential inquiry. They can be situated in different parts of a SQL explanation, comprising the WHERE provision, FROM proviso, SELECT statement, or perhaps the HAVING condition.

 

2. Assessment: Subqueries are assessed inside before the external question is executed. The final product of the subquery is then utilized by the external inquiry to similarly sift through or deal with the data once more.

 

3. Relationship: Subqueries can be connected or uncorrelated. In a related subquery, the inward inquiry references sections from the external question, permitting the subquery to be achieved over and over for each line handled by the external question. In assessment, uncorrelated subqueries are autonomous of the external inquiry and are done most straightforwardly once.

4. Types: Subqueries can be named fundamentally based on their bring cost back:

  • Scalar Subquery: Returns a solitary value and can be utilized anyplace an articulation is anticipated, alongside in the SELECT posting or WHERE statement.
  • Column Subquery: Returns one or additional lines of records and might be used in circumstances that expect a bunch of values, which remembers FOR, EXISTS, or correlation administrators.
  • Table Subquery: Returns a whole outcome set and can be utilized as a got table inside the FROM condition of the guideline question.

5. Performance: While subqueries give adaptability, they can likewise influence general execution, exceptionally if inadequately advanced or utilized unreasonably. It's critical to mindfully plan and streamline subqueries to ensure productive question execution.

 

Read more: What is sub-query in SQL Server? Explain its Properties