0% found this document useful (0 votes)
255 views3 pages

Practice Question For AdventureWorks2022 Database

Uploaded by

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

Practice Question For AdventureWorks2022 Database

Uploaded by

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

--Practice Question for AdventureWorks2022 database

--1. Inner Join:


-- - Question: Write a query to retrieve the `BusinessEntityID`, `JobTitle`,
`FirstName`, and `LastName` of all employees by joining the
`HumanResources.Employee` and `Person.Person` tables on `BusinessEntityID`.

--2. Left Join:


-- - Question: Write a query to list all persons with their addresses, including
those who do not have an address. Use the `Person.Person` table and the
`Person.Address` table, joining on `BusinessEntityID`.

--3. Right Join:


-- - Question: Write a query to list all product reviews along with the names of
the reviewers. Include all reviews even if the reviewer’s name is not available.
Use the `Production.ProductReview` table and the `Person.Person` table, joining on
`ReviewerID`.

--4. Full Outer Join:


-- - Question: Write a query to list all employees and their associated
departments. Include employees without departments and departments without
employees. Use the `HumanResources.Employee` and `HumanResources.Department`
tables, joining on `DepartmentID`.

--5. Self Join:


-- - Question: Write a query to find all pairs of employees who share the same
manager. Use the `HumanResources.Employee` table and perform a self join on
`ManagerID`.

--6. Cross Join:


-- - Question: Write a query to list all possible combinations of product
categories and product subcategories. Use the `Production.ProductCategory` and
`Production.ProductSubcategory` tables.

--7. Natural Join:


-- - Question: Although SQL Server does not support a natural join directly,
simulate a natural join by listing all `BusinessEntityID`, `FirstName`, and
`LastName` from the `Person.Person` table and their associated email addresses from
the `Person.EmailAddress` table.

--8. Join with Aggregates:


-- - Question: Write a query to find the total sales amount for each sales
person. Use the `Sales.SalesOrderHeader` and `Sales.SalesPerson` tables, joining on
`SalesPersonID`.

--9. Join with Multiple Tables:


-- - Question: Write a query to retrieve the `ProductID`, `Name`, `SalesOrderID`,
and `OrderDate` for all sales orders. Use the `Sales.SalesOrderDetail`,
`Production.Product`, and `Sales.SalesOrderHeader` tables, joining on `ProductID`
and `SalesOrderID`.

--10. Join with Subquery:


-- - Question: Write a query to find the names of employees who have placed an
order. Use a subquery to find the `EmployeeID` from the `Sales.SalesOrderHeader`
table and join it with the `HumanResources.Employee` and `Person.Person` tables to
get the `FirstName` and `LastName`.

-- Set Operators Questions


--1. UNION:
-- - Question: Write a query to list all `BusinessEntityID` values that appear in
either the `Person.Person` table or the `Sales.Customer` table, or both.

--2. UNION ALL:


-- - Question: Write a query to list all `BusinessEntityID` values, including
duplicates, from both the `Person.Person` table and the `Sales.Customer` table.

--3. INTERSECT:
-- - Question: Write a query to find all `BusinessEntityID` values that are
present in both the `Person.Person` table and the `Sales.Customer` table.

--4. EXCEPT:
-- - Question: Write a query to find all `BusinessEntityID` values that are
present in the `Person.Person` table but not in the `Sales.Customer` table.

--5. UNION with additional columns:


-- - Question: Write a query to list all `FirstName` and `LastName` combinations
from both the `Person.Person` table and the `HumanResources.Employee` table. Ensure
there are no duplicates.

--6. UNION ALL with filtering:


-- - Question: Write a query to list all `EmailAddress` values from the
`Person.EmailAddress` table and `Sales.SalesPersonEmailAddress` table, including
duplicates.

--7. INTERSECT with condition:


-- - Question: Write a query to find all `ProductID` values that are in both the
`Sales.SalesOrderDetail` table and the `Production.Product` table and have a
`ProductID` less than 1000.

--8. EXCEPT with condition:


-- - Question: Write a query to find all `SalesOrderID` values in the
`Sales.SalesOrderHeader` table that are not in the `Sales.SalesOrderDetail` table
and where the `OrderDate` is in the year 2022.

--9. Complex UNION:


-- - Question: Write a query to combine the `Name` from `Production.Product` and
`Production.ProductSubcategory` tables. Ensure that the combined list is unique.

--10. Complex EXCEPT:


-- - Question: Write a query to list all `EmployeeID` values from the
`HumanResources.Employee` table that do not appear in the `Sales.SalesOrderHeader`
table, ensuring that the list only includes active employees.

You might also like