sql commands
sql commands
FROM,
This gets the name and age of all students from the
students table.
Select name from Students
Field name Table name
https://sqlfiddle.com/sql-server/online-compiler?id=bf6e7886-ba1c-
4961-9b6e-8eb4b9500682
WHERE
Filters records (only shows data that meets a condition).
• https://sqlfiddle.com/sql-server/online-compiler?id=5ada5e81-99f8-
463e-ac47-c1b439b8d631
ORDER BY
Purpose: Sorts the result in ascending or descending order.
• https://sqlfiddle.com/sql-server/online-compiler?id=412a84c9-630a-4
e06-8a89-5f5480e866a9
• https://sqlfiddle.com/sql-server/online-compiler?id=23cf6b42-6c77-
42af-bf8b-664b14894711
GROUP BY
Purpose: Groups rows with the
same values in a column.
SELECT column_name, aggregate_function(column_name)
FROM table_name
GROUP BY column_name;
https://sqlfiddle.com/sql-server/online-compiler?id=54472182-65ff-44b
e-b8f4-e0b4c5c6df79
SELECT Grade, COUNT(*) FROM students GROUP BY Grade;
SUM
Adds values in a numeric column.
🎯 Table 2: classes
class_id class_name
101 Computer Sci
102 Maths
103 Physics
Notice:
•Student Clara is matched with class Computer Sci because her class_id is 101.
•The class with ID 103 (Physics) is not shown because no student belongs to it.
•This is what makes it an "INNER" join — it only returns matching records.
• The UPDATE command is used to change the data. If the band ABC recruited an
extra member , SQL would make the change needed.
• UPDATE Band
• SET NumberOfMembers = 6
• WHERE BandName= “ABC”