in Technology by
What is a Subquery? What are its types?

1 Answer

0 votes
by

A subquery is a query within another query, also known as nested query or inner query . It is used to restrict or enhance the data to be queried by the main query, thus restricting or enhancing the output of the main query respectively. For example, here we fetch the contact information for students who have enrolled for the maths subject:

SELECT name, email, mob, address
FROM myDb.contacts
WHERE roll_no IN (
	 SELECT roll_no
	 FROM myDb.students
	 WHERE subject = 'Maths');

There are two types of subquery - Correlated and Non-Correlated.

  • correlated subquery cannot be considered as an independent query, but it can refer the column in a table listed in the FROM of the main query.
  • non-correlated subquery can be considered as an independent query and the output of subquery is substituted in the main query.

Related questions

0 votes
    For four days now I´ve been trying to perform a query in my database. Heres the problem: I have a ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 23, 2022 in Education by JackTerrance
0 votes
    A non-correlated subquery can be defined as________ (a) A set of sequential queries, all of which ... Predicate Reads topic in division Concurrency Control of Database Management...
asked Oct 10, 2021 in Education by JackTerrance
0 votes
    What is sniffing and what are its types?...
asked Feb 16, 2021 in Technology by JackTerrance
0 votes
    What is User-defined function? What are its various types?...
asked Dec 11, 2020 in Technology by JackTerrance
0 votes
    What is Dependency Injection and its types in laravel?...
asked Sep 30, 2021 in Technology by JackTerrance
0 votes
    What is Ansible Inventory and its types?...
asked Jul 29, 2021 in Technology by JackTerrance
0 votes
    What do you mean by Trojan and explain its types?...
asked Feb 15, 2021 in Technology by JackTerrance
0 votes
    What is an Index? Explain its different types....
asked Dec 9, 2020 in Technology by JackTerrance
0 votes
    What is a Join? List its different types....
asked Dec 8, 2020 in Technology by JackTerrance
0 votes
    What is BLOB and its types in MySQL?...
asked Nov 30, 2020 in Technology by JackTerrance
0 votes
    What is Nationalism? Explain its types. Please answer the above question....
asked Aug 4, 2022 in Education by JackTerrance
0 votes
    What is Nationalism? Explain its types. Please answer the above question....
asked Aug 3, 2022 in Education by JackTerrance
0 votes
    I have a function value(x) which is overloaded for many types such that: double value(double x) { return x; } double ... [-Wreturn-local-addr] in the following code: Matrix33 m; m...
asked Apr 24, 2022 in Education by JackTerrance
0 votes
    .Computer can do different types of task, it show its which characteristics? A.. Fast B.. Accuracy C.. Diligence D.. Versatility Select the correct answer from above options...
asked Dec 31, 2021 in Education by JackTerrance
0 votes
    What is Jenkins, and what are its best features?...
asked Oct 1, 2021 in Technology by JackTerrance
...