1742292145_MySQL_Codes
1742292145_MySQL_Codes
SQL
Commands
MySQL SELECT Statement
SELECT CustomerName, City, Country FROM Customers;
SELECT MAX(Price)
FROM Products;
MySQL MIN() and MAX() with AS
SELECT MIN(Price) AS SmallestPrice
FROM Products;
SELECT AVG(Price)
FROM Products;
SELECT SUM(Quantity)
FROM OrderDetails;
MySQL LIKE Operator
• The LIKE operator is used in a WHERE clause to search for a
specified pattern in a column.
• There are two wildcards often used in conjunction with the LIKE
operator:
The percent sign and the underscore can also be used in combinations!
LIKE operators with '%' and '_' wildcards
MySQL LIKE Operator
SELECT * FROM Customers
WHERE CustomerName LIKE 'a%’;
The CROSS JOIN keyword returns all records from both tables (table1 and table2).
Find OUT
SELECT Orders.OrderID, Customers.CustomerID
FROM Orders
INNER JOIN Customers ON Orders.CustomerID =
Customers.CustomerID;
The LEFT JOIN keyword returns all records from the left table (table1), and the matching records (if any) from the right
table (table2).
Find OUT
SELECT Orders.OrderID, Customers.CustomerID
DISTINCT CustomerID in
FROM Orders Orders Table: 89
RIGHT JOIN Customers DISTINCT OrderID in
ON Orders.CustomerID = Customers.CustomerID Orders Table: 830
The RIGHT JOIN keyword returns all records from the right table (table2), and the matching records (if any) from the left table
(table1).
The UNION operator selects only distinct values by default. To allow duplicate values, use UNION ALL
Which will be the Result for Union and Union ALL ??
• The GROUP BY statement groups rows that have the
same values into summary rows, like "find the number of
customers in each country".
• The GROUP BY statement is often used with aggregate
functions (COUNT(), MAX(), MIN(), SUM(), AVG()) to group
the result-set by one or more columns.
SQL SQL
Commands
Commands