

In this blog post, we will explore some basic SQL operations to manage and analyze employee data effectively. We will use the following three common operations as examples:
- Retrieving top records with specific columns.
- Selecting specific columns from a table.
- Calculating the average of a numeric column.
Retrieving Top Records with Specific Columns
To display the top 1000 records from the EmployeeDemographics table, along with specific columns like EmployeeID, FirstName, LastName, Age, and Gender, you can use the SELECT statement:
SELECT TOP (1000) [EmployeeID],
[FirstName],
[LastName],
[Age],
[Gender]
FROM [SQL Tutorial].[dbo].[EmployeeDemographics];
This query fetches the first 1000 records from the table, which can be useful when working with large datasets.
Selecting Specific Columns from a Table
To retrieve only the FirstName and LastName columns from the EmployeeDemographics table, use the following query:
SELECT FirstName, LastName
FROM [SQL Tutorial].[dbo].[EmployeeDemographics];
This query helps focus on the key identifying information of employees without overloading the output with unnecessary columns.
Calculating the Average of a Numeric Column
To calculate the average salary of employees, you can use the AVG function on the Salary column from the EmployeeSalary table:
SELECT AVG(Salary)
FROM [SQL Tutorial].[dbo].[EmployeeSalary];
The result will give you the average salary, which is crucial for analysis like budgeting or determining competitive pay rates.
Example Output
Query: Selecting FirstName and LastName
The result might look like this:
| FirstName | LastName |
|---|---|
| Muhammet | Sahin |
| Dwight | Schrute |
| Angela | Martin |
| Toby | Flenderson |
| Michael | Scott |
Query: Calculating Average Salary
For the salary query, the output might be:
| (No column name) |
|---|
| 48555 |
This indicates that the average salary is 48,555.
Conclusion
By mastering these basic SQL queries, you can efficiently retrieve, filter, and analyze employee data for meaningful insights. SQL remains a powerful tool for database management and analysis, and practicing these queries will strengthen your foundational skills. Happy querying!