New Text Document
New Text Document
);
W3 Q1
CREATE TABLE Products (
ProductID INT PRIMARY KEY AUTO_INCREMENT,
ProductName VARCHAR(100),
Price DECIMAL(10, 2),
Stock INT
);
INSERT INTO Products (ProductName, Price, Stock) VALUES ('Laptop', 999.99, 50);
w4
SELECT *
FROM Products
ORDER BY Price DESC;
SELECT *
FROM Products
WHERE ProductName LIKE 'L%';
SELECT *
FROM Products
WHERE Price BETWEEN 100 AND 500;
SELECT *
FROM Products
ORDER BY Price DESC
LIMIT 3;
w5
CREATE TABLE Products (
ProductID INT PRIMARY KEY AUTO_INCREMENT,
ProductName VARCHAR(50),
Price DECIMAL(10, 2)
);
SELECT
c.CustomerName,
p.ProductName,
o.OrderDate,
o.Quantity
FROM Customers c
INNER JOIN Orders o ON c.CustomerID = o.CustomerID
INNER JOIN Products p ON p.ProductID = o.ProductID;
SELECT
c.CustomerName,
p.ProductName,
o.OrderDate,
o.Quantity
FROM Customers c
LEFT JOIN Orders o ON c.CustomerID = o.CustomerID
LEFT JOIN Products p ON p.ProductID = o.ProductID;
SELECT
c.CustomerName,
p.ProductName,
o.OrderDate,
o.Quantity
FROM Customers c
RIGHT JOIN Orders o ON c.CustomerID = o.CustomerID
RIGHT JOIN Products p ON p.ProductID = o.ProductID;
SELECT
c.CustomerName,
p.ProductName,
o.OrderDate,
o.Quantity
FROM Customers c
LEFT JOIN Orders o ON c.CustomerID = o.CustomerID
LEFT JOIN Products p ON p.ProductID = o.ProductID
UNION
SELECT
c.CustomerName,
p.ProductName,
o.OrderDate,
o.Quantity
FROM Customers c
RIGHT JOIN Orders o ON c.CustomerID = o.CustomerID
RIGHT JOIN Products p ON p.ProductID = o.ProductID
WHERE c.CustomerID IS NULL;