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

SQL Queries

SQL Queries DBMS

Uploaded by

yashpatilyp2004
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

SQL Queries

SQL Queries DBMS

Uploaded by

yashpatilyp2004
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Question:

Write a SQL query to retrieve all employees from the "Employees" table who are in the "Marketing" department.
Answer:

sql Copy code

SELECT * FROM Employees WHERE Department = 'Marketing';

Question:
Write a SQL query to calculate the total number of orders placed in the "Orders" table.
Answer:

sql Copy code

SELECT COUNT(*) AS TotalOrders FROM Orders;

Question:
Write a SQL query to update the salary of an employee with the ID 101 to $5000.
Answer:

sql Copy code

UPDATE Employees SET Salary = 5000 WHERE EmployeeID = 101;

Question:
Write a SQL query to delete all orders placed before January 1, 2022, from the "Orders" table.
Answer:

sql Copy code

DELETE FROM Orders WHERE OrderDate < '2022-01-01';


Question:
Write a SQL query to retrieve the average salary of all employees in the "Finance" department.
Answer:

sql Copy code

SELECT AVG(Salary) AS AverageSalary FROM Employees WHERE Department = 'Finance';

Question:
Write a SQL query to insert a new record into the "Customers" table with the following details: CustomerID = 101, Name = 'John Smith', and City
= 'New York'.
Answer:

sql Copy code

INSERT INTO Customers (CustomerID, Name, City) VALUES (101, 'John Smith', 'New York');

Question:
Write a SQL query to retrieve the highest salary among all employees.
Answer:

sql Copy code

SELECT MAX(Salary) AS HighestSalary FROM Employees;

Question:
Write a SQL query to retrieve the names of all products in the "Products" table sorted in ascending order of their prices.
Answer:

sql Copy code

SELECT ProductName FROM Products ORDER BY Price ASC;


Question:
Write a SQL query to update the quantity of a product with the ID 102 to 50.
Answer:

sql Copy code

UPDATE Products SET Quantity = 50 WHERE ProductID = 102;

Question:
Write a SQL query to retrieve the names of all employees along with their corresponding department names.
Answer:

sql Copy code

SELECT e.Name AS EmployeeName, d.Name AS DepartmentName FROM Employees e INNER JOIN Departments d ON e.DepartmentID =
d.DepartmentID;

You might also like