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

Difference Between Joins and Sub-Query

Joins combine rows from tables based on matching conditions, while subqueries return a singular value or result set that is used in the main query. A join displays related data from multiple tables, but a subquery calculates a value for filtering or grouping. Additionally, a join must be part of a select statement, whereas a subquery can return a standalone result.
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views

Difference Between Joins and Sub-Query

Joins combine rows from tables based on matching conditions, while subqueries return a singular value or result set that is used in the main query. A join displays related data from multiple tables, but a subquery calculates a value for filtering or grouping. Additionally, a join must be part of a select statement, whereas a subquery can return a standalone result.
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 3

Difference between joins and

sub-query
• Joins and subqueries are both be used to query
data from different tables and may even share
the same query plan, but there are many
differences between them
• A common use for a subquery may be to
calculate a summary value for use in a
query. For instance we can use a subquery to
help us obtain all products have a greater than
average product price
• Sub query can give result as singular value or as
row set but join can only give rows

• Contrast this with a join whose main purpose is


to combine rows from one or more tables based
on a match condition. For example, we can use
a join display product names and models
.
• Select is an integral part of join it cannot stand
without it
• we’re using an INNER JOIN to match rows from both the
Product and ProductModel tables. that the column
ProductModel. Name is available for use throughout the
query.

• The combined row set is then available by the select


statement for use to display, filter, or group by the
columns.

• This is different than the subquery. There the subquery


returns a result, which is immediately used.

• Note that the join is an integral part of the select


statement. It cannot stand on its own as a subquery can.

You might also like