• techinterviewhero.com

Top 10 Basic SQL Queries

Let’s start with SQL interview questions and answers for the first blog topic: “Basic SQL Queries”.

Question 1: What is SQL and why is it used?

Answer:

SQL stands for Structured Query Language. It is a standard programming language used for managing and manipulating relational databases. SQL is used to perform tasks such as retrieving data from databases, inserting new records, updating existing records, and deleting records. It provides a simple and efficient way to interact with databases.

Question 2: What are the basic components of an SQL query?

Answer:

The basic components of an SQL query include:

  1. SELECT: Used to specify the columns you want to retrieve data from.
  2. FROM: Specifies the table from which you want to retrieve data.
  3. WHERE: Filters the rows based on specific conditions.
  4. GROUP BY: Groups the rows based on one or more columns.
  5. HAVING: Filters the groups based on specific conditions.
  6. ORDER BY: Sorts the result set based on one or more columns.
  7. LIMIT: Limits the number of rows returned by the query.

 

Question 3: Write an SQL query to retrieve all columns from a table named “employees”.

Answer:   

SELECT * FROM employees; http://microsoft sql.com

 

Question 4: Write an SQL query to retrieve only the “name” and “age” columns from a table named “students”.

Answer:

SELECT name, age FROM students;

Question 5: Write an SQL query to retrieve employees whose age is greater than 30.

Answer:

SELECT * FROM employees WHERE age > 30;

Question 6: Write an SQL query to retrieve the total number of employees in the “employees” table.

 Answer:

SELECT COUNT(*) AS total_employees FROM employees;

Question 7: Write an SQL query to retrieve the highest salary from the “salaries” table.

 Answer:

SELECT MAX(salary) AS highest_salary FROM salaries;

Question 8: Write an SQL query to retrieve the average age of employees.

Answer:

SELECT AVG(age) AS average_age FROM employees;

Question 9: Write an SQL query to retrieve employees sorted by their salary in descending order.

Answer:

SELECT * FROM employees ORDER BY salary DESC;

Question 10: Write an SQL query to retrieve the top 5 highest paid employees.

Answer:

These questions cover some of the fundamental aspects of SQL queries, providing a solid foundation for beginners and a refresher for experienced SQL developers.

https://techinterviewhero.com/

1 thought on “Top 10 Basic SQL Queries

Leave a Reply

Your email address will not be published. Required fields are marked *