What is an SQL query?
An SQL query is an instruction written in SQL, which a user or program uses to reach a database, to retrieve, change, or manage data.
The main points
- Retrieving data: a query can pull information from tables. Example:
sql
SELECT Name, Age FROM Employees WHERE DepartmentID = 101;- shows the names and ages of employees in a specific department.
- Adding data: a query can insert new records into a table. Example:
sql
INSERT INTO Employees (Name, Age, DepartmentID) VALUES ('Anna', 28, 102);- Changing data: a query can update existing records. Example:
sql
UPDATE Employees SET Age = 29 WHERE Name = 'Anna';- Deleting data: a query can delete records. Example:
sql
DELETE FROM Employees WHERE Name = 'Anna';- Managing structure: queries can create or change tables and the relationships between them (DDL, Data Definition Language).
Put simply, an SQL query is a way to "talk" to a database, to get the data you need and manage it.
Short Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.