Queries in SQL

Elementary SQL Queries

Let's Journey Through Elementary SQL Queries

Understand them in an easy manner. Examples will be provided in real-time.

1. SELECT Query:

Explanation: Query is akin to asking the database to show specified data.

Example: Consider a scenario. You have a list of students. You want to see all names and ages from a table named "Students."

SELECT name, age FROM Students;

2. WHERE Clause:

Explanation: WHERE Clause is integral in SQL queries. It allows for filtering of data. You can ask for students who fall under a certain age bracket or for students with a particular name.

Example: Let's imagine you wish to only see students who are 10 years old.

SELECT name, age FROM Students WHERE age = 10;

3. INSERT Query:

Explanation: It allows you to incorporate new data into a table.

Example: When there is a new student, say "Sara," who is 11 years old. You can add her to the table.

INSERT INTO Students (name, age) VALUES ('Sara', 11);

4. UPDATE Query:

Explanation: Lets you alter current data content.

Example: In a situation where the age of "Sara" was incorrectly entered. You can fix it easily. Just update it with the right one.

UPDATE Students SET age = 12 WHERE name = 'Sara';

5. DELETE Query:

Explanation: Eradicates information from a table.

Example: If you realize that there's a double entry for a student named "Tom," execute deletion for one of those.

DELETE FROM Students WHERE name = 'Tom' AND age = 13;

6. ORDER BY Clause:

Explanation: It assists in arranging outcomes in a particular manner.

Example: You may desire to view students in alphabetical order. They can be ordered by name.

SELECT name, age FROM Students ORDER BY name;

7. GROUP BY Clause:

Explanation: This enables you to group resembling data together. You can also carry out calculations on such data.

Example: Should you wish to determine how many students are in each age group:

SELECT age, COUNT(*) FROM Students GROUP BY age;

Summary:

These are elementary SQL queries. They serve as questions or guidelines. You can put them to use for managing data in a database. SQL is a robust resource for controlling and extracting data. Queries allow you to obtain necessary information from a database.