Concept Of SQL Server Part III

Concept Of SQL Server

Union :
  • Union is used to combine data of one or more tables.

  • Union only distinct values are allowed.

  • The following SQL statement returns the Id, FirstName, LastName (only distinct values) from both the "tblCustomer" and the "tblCustomerExpired" table :

Two Table :

tblCustomer

tblCustomerExpired

Example :

Union all :
  • Union all is used to combine data of one or more tables.

  • Union all duplicates values are allowed.

  • The following SQL statement returns the Id, FirstName, LastName (duplicate values also)from both the "tblCustomer" and the "tblCustomerExpired" table :

Two Table :

tblCustomer

tblCustomerExpired

Example :

Group By Clause :
  • Group by clause is used to combines the groups rows that have the same values into rows.

  • The Group By clause is used with aggregate functions (COUNT(), MAX(), MIN(), SUM(), AVG()) to group the result-set by one or more columns.

tblCustomer

Example :

SubQuery :
  • Subquery is nothing but query inside a query.

  • Inner query is called as subquery and embedded within the Where clause. 

In Keyword :
  • In keyword is used to retrieve rows in subquery based on the match of values given in a list.

Two Table :

tblAddress

tblCustomer

Example :

Correlated SubQuery :
  • Correlated Subquery is a subquery that uses values from the outer query.

Example :

Questions :

1) What are the Use of correlated Queries ?
  • Correlated subqueries are used for row-by-row processing. Each subquery is executed once for every row of the outer query.

  • A correlated subquery is evaluated once for each row processed by the parent statement. The parent statement can be a select statement.

2) What is the Difference between Inner join and Subquery ?

Inner join :
  • Inner join is used to combine rows from two or more tables.

  • Inner joins can be used to return rows. 

Subquery :
  • Subquery is used to combine data from different tables into a single result. 

  • Subqueries can be used to return either a single value or a row set.

Comments

Popular posts from this blog

Basic Concept In C Sharp Day 16

Understanding C Sharp Day 18

Concept In Angular Day 14