SQL Questions
SQL Questions
UPDATE Products
SET Price = Price * 1.10
WHERE ProductID = 1;
SELECT Employees.First
Name, Departments.DepartmentName
FROM Employees
LEFT JOIN Departments ON Employees.DepartmentID = Departments.DepartmentID;
**Example:**
```sql
SELECT Orders.OrderID, Products.ProductName
FROM Orders
RIGHT JOIN Products ON Orders.ProductID = Products.ProductID;
5. What is a subquery?
Answer: A query nested inside another query. Subqueries are used to retrieve data that will be used in the main query.
Example:
SELECT FirstName
FROM Employees
WHERE EXISTS (
SELECT 1
FROM Orders
WHERE Orders.EmployeeID = Employees.EmployeeID
);
BEGIN TRANSACTION;
UPDATE Accounts SET Balance = Balance - 100 WHERE AccountID = 1;
UPDATE Accounts SET Balance = Balance + 100 WHERE AccountID = 2;
COMMIT;
BEGIN TRANSACTION;
UPDATE Products SET Price = Price - 50 WHERE ProductID = 1;
ROLLBACK;
😗*
sql SELECT ProductID FROM Products WHERE NOT EXISTS ( SELECT 1 FROM Orders WHERE Orders.ProductID = Products.Pr
30. How do you implement data integrity with FOREIGN KEY constraints?
Answer: Ensures that a value in one table corresponds to a value in another table, maintaining referential integrity.
Example: