SQL Commands
SQL Commands
com/important-questions-class-
12-computer-science-python-networking-open-
source-concepts/
https://youtu.be/zehwgTB0vV8
https://www.youtube.com/shorts/GlUzUuGvhEY?
feature=share
https://youtu.be/sZzszp7wOPE
2. Ultrasonic sensor
3. Servo motor
4. Jumper wires
5. Battery
6. Dustbin
7. Cardboard
8. Adhesive
9. Scissor
Syntax
SELECT column1, column2, ...
FROM table_name
ORDER BY column1, column2, ... ASC|DESC;
DESC
The ORDER BY keyword sorts the records in ascending
order by default. To sort the records in descending order,
use the DESC keyword.
Order Alphabetically
For string values the ORDER BY keyword will order
alphabetically:
Example
Sort the products by ProductName in reverse order:
SELECT * FROM Products
ORDER BY ProductName DESC;
Example
SELECT * FROM Customers
WHERE Country = 'Germany'
AND City = 'Berlin'
AND PostalCode > 12000;
Example
Select all Spanish customers that starts with either "G" or
"R":
SELECT * FROM Customers
WHERE Country = 'Spain' AND (CustomerName LIKE 'G
%' OR CustomerName LIKE 'R%');
The OR operator is used to filter records based on
more than one condition, like if you want to return all
customers from Germany but also those from Spain:
Example
UPDATE Customers
SET ContactName='Juan'
WHERE Country='Mexico';
Delete a Table
To delete the table completely, use the DROP
TABLE statement:
SELECT MIN(Price)
FROM Products;
SELECT MAX(Price)
FROM Products;
The SQL COUNT() Function
The COUNT() function returns the number of rows that
matches a specified criterion.
Example
Return the sum of the Quantity field for the product
with ProductID 11:
SELECT SUM(Quantity)
FROM OrderDetails
WHERE ProductId = 11;
Example
SELECT OrderID, SUM(Quantity) AS [Total Quantity]
FROM OrderDetails
GROUP BY OrderID;
Example
Use an expression inside the SUM() function:
SELECT SUM(Quantity * 10)
FROM OrderDetails;
The SQL AVG() Function
The AVG() function returns the average value of a
numeric column.
SQL JOIN
A JOIN clause is used to combine rows from two or more
tables, based on a related column between them.
Let's look at a selection from the "Orders" table:
10308 2 1996-09-18
10309 37 1996-09-19
10310 77 1996-09-20
Example
SELECT COUNT(CustomerID), Country
FROM Customers
GROUP BY Country
HAVING COUNT(CustomerID) > 5
ORDER BY COUNT(CustomerID) DESC;