You are on page 1of 4

Faculty of Computing and Information Technology (FCIT)

Department of Computing Indus University, Karachi

NAME OF STUDENT: ___________________ID No: ________________

LAB # 04 Tasks
Self
Joins
1. Write a query to list the names of employees that belongs to the same location as the employee
named Nancy.

2. Write a query to list the name of employees in front of the names of their mangers.

Right Join / Left Join


3. Execute the script named Customer_Order.sql.

/****** Object: Table [dbo].[tbl_Customers] Script Date: 2/29/2016 10:51:59 AM ******/


SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER
ON GO
CREATE TABLE [dbo].
[tbl_Customers]( [ID] [int]
NULL,
[Name] [nvarchar](max) NULL,
[Age] [int] NULL,
[Address] [nvarchar](max)
NULL, [Salary] [decimal](18, 0)
NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
/****** Object: Table [dbo].[tbl_Orders] Script Date: 2/29/2016 10:51:59 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER
ON GO
CREATE TABLE [dbo].[tbl_Orders](
[OID] [int] NULL,
[Date] [datetime] NULL,
[Customer_Id] [int]
NULL, [Amount] [int]
NULL
) ON [PRIMARY]

GO
INSERT [dbo].[tbl_Customers] ([ID], [Name], [Age], [Address], [Salary]) VALUES (1, N'Sidra', 33,
N'Karachi', CAST(2000 AS Decimal(18, 0)))
INSERT [dbo].[tbl_Customers] ([ID], [Name], [Age], [Address], [Salary]) VALUES (2, N'Haroon', 30,
N'Lahore', CAST(2000 AS Decimal(18, 0)))
INSERT [dbo].[tbl_Customers] ([ID], [Name], [Age], [Address], [Salary]) VALUES (3, N'Qasim', 29,
Faculty of Computing and Information Technology (FCIT)
Department of Computing Indus University, Karachi

NAME OF STUDENT: ___________________ID No: ________________

N'Lahore', CAST(3000 AS Decimal(18, 0)))


Faculty of Computing and Information Technology (FCIT)
Department of Computing Indus University, Karachi

NAME OF STUDENT: ___________________ID No: ________________

INSERT [dbo].[tbl_Customers] ([ID], [Name], [Age], [Address], [Salary]) VALUES (4, N'Ali', 28,
N'Islamabad', CAST(9000 AS Decimal(18, 0)))
INSERT [dbo].[tbl_Customers] ([ID], [Name], [Age], [Address], [Salary]) VALUES (5, N'Bilal', 29,
N'Karachi', CAST(6000 AS Decimal(18, 0)))
INSERT [dbo].[tbl_Customers] ([ID], [Name], [Age], [Address], [Salary]) VALUES (6,
N'Asif', 31, N'Islamabad', CAST(9000 AS Decimal(18, 0)))
INSERT [dbo].[tbl_Customers] ([ID], [Name], [Age], [Address], [Salary]) VALUES (7, N'Shahrukh', 34,
N'Karachi', CAST(4000 AS Decimal(18, 0)))
INSERT [dbo].[tbl_Orders] ([OID], [Date], [Customer_Id], [Amount]) VALUES (101, CAST(N'2015-01-
01 00:00:00.000' AS DateTime), 1, 100)
INSERT [dbo].[tbl_Orders] ([OID], [Date], [Customer_Id], [Amount]) VALUES (102, CAST(N'2015-01-
02 00:00:00.000' AS DateTime), 1, 100)
INSERT [dbo].[tbl_Orders] ([OID], [Date], [Customer_Id], [Amount]) VALUES (103, CAST(N'2015-02-
04 00:00:00.000' AS DateTime), 2, 100)
INSERT [dbo].[tbl_Orders] ([OID], [Date], [Customer_Id], [Amount]) VALUES (104, CAST(N'2015-02-
05 00:00:00.000' AS DateTime), 4, 100)

4. Write a query to display the following records of all the customers along with their order details (if
any).

5. Write a query to display all the orders placed by a customers.

6. Name the store that offer initial customer discount.

7. Name all the employees working in New York.

8. List the stores of all titles.

9. List all the employees working for “New Moon Books”.

10. Who is the production manager of “Lucerne Publishing”?

11. Make the list of all Authors sales.

12. Name the publisher that has authors whose name ends with “e”.

13. Which publisher has got most titles in store in Seattle?

14. List all the authors available in Barnum’s store.


Faculty of Computing and Information Technology (FCIT)
Department of Computing Indus University, Karachi

NAME OF STUDENT: ___________________ID No: ________________

Set Operations

15. Combine query 3 and query 4 in a single table by applying UNION operation. Briefly discuss
the results.
16. Combine query 3 and query 4 in a single table by applying UNION ALL operation. Briefly discuss
the results.
17. Combine query 3 and query 4 in a single table by applying INTERSECT operation. Briefly discuss
the results.
18. Combine query 3 and query 4 in a single table by applying EXCEPT operation. Briefly discuss
the results.

You might also like