DEV Community

Cover image for SQL Basic Question for interview
Jaimin Bariya
Jaimin Bariya

Posted on

SQL Basic Question for interview

Let's come to the point.

I have created an Awesome SQL Interview GitHub repo to prepare for interview questions and practice SQL queries. I have divided the SQL queries into three sections: Basic (L0), Intermediate (L1), and Advanced (L2). This is the solution for the basic section.


L0: Basic SQL

  • Questions related to basic SQL commands such as SELECT, INSERT, UPDATE, and DELETE.
  • Queries related to basic data manipulation and retrieval from simple tables.

Query Questions:

  1. How do you display all columns and rows from the customers table?
  2. Write a query to retrieve only the customerName and phone from the customers table.
  3. How do you list all rows where country is 'USA' in the customers table?
  4. Write a query to find all products in the products table with a buyPrice less than 50.
  5. How do you fetch all orders with a status of 'Shipped' from the orders table?
  6. Write a query to display the productName and quantityInStock for all products in the products table.
  7. How do you find the distinct country values in the customers table?
  8. Write a query to count the total number of customers in the customers table.
  9. How do you retrieve all employees whose jobTitle is 'Sales Rep'?
  10. Write a query to sort the products table by productName in ascending order.
  11. How do you fetch the customerName and city of all customers located in 'Paris'?
  12. Write a query to display the top 10 orders from the orders table based on the orderDate.
  13. How do you retrieve all offices located in the USA?
  14. Write a query to display all employees who work in the office located in 'San Francisco'.
  15. How do you calculate the total number of orders placed in the orders table?
  16. Write a query to display the productName of all products in the products table where productLine is 'Classic Cars'.
  17. How do you find the customerName of all customers whose creditLimit is greater than 50,000?
  18. Write a query to fetch all products that have a quantityInStock between 10 and 100.
  19. How do you retrieve all orders placed in the year 2003?
  20. Write a query to display the employeeNumber and firstName of employees whose last names start with 'B'.

Solution with explanation

  1. How do you display all columns and rows from the customers table?
    Image description

  2. Write a query to retrieve only the customerName and phone from the customers table.
    Jaimin Bariya, Cloud Boy

  3. How do you list all rows where country is 'USA' in the customers table?
    Jaimin Bariya, Cloud Boy

  4. Write a query to find all products in the products table with a buyPrice less than 50.
    Jaimin Bariya, Cloud Boy

  5. Fetch all orders with a status of 'Shipped' from the orders table.
    Jaimin Bariya, Cloud Boy

  6. Display the productName and quantityInStock for all products in the products table.
    Jaimin Bariya, Cloud Boy

  7. Find the distinct country values in the customers table.
    Jaimin Bariya, Cloud Boy

  8. Count the total number of customers in the customers table.
    Jaimin Bariya, Cloud Boy

  9. Retrieve all employees whose jobTitle is 'Sales Rep'?
    Jaimin Bariya, Cloud Boy

  10. Sort the products table by productName in ascending order.
    Image description

  11. Fetch the customerName and city of all customers located in 'Paris'.
    Jaimin Bariya, Cloud Boy

  12. Display the top 10 orders from the orders table based on the orderDate.
    Jaimin Bariya, Cloud Boy

  13. Retrieve all offices located in the USA.
    Jaimin Bariya, Cloud Boy

  14. Display all employees who work in the office located in 'San Francisco'.
    Jaimin Bariya, Cloud Boy

  15. Calculate the total number of orders placed in the orders table.
    Jaimin Bariya, Cloud Boy

  16. Display the productName of all products in the products table where productLine is 'Classic Cars'.
    Jaimin Bariya, Cloud Boy

  17. Find the customerName of all customers whose creditLimit is greater than 50,000.
    Jaimin Bariya, Cloud Boy

  18. Fetch all products that have a quantityInStock between 10 and 100.

    Jaimin Bariya, Cloud Boy

  19. Retrieve all orders placed in the year 2003?
    Jaimin Bariya, Cloud Boy

  20. Display the employeeNumber and firstName of employees whose last names start with 'B'.
    Jaimin Bariya, Cloud Boy


Hey, My name is Jaimin Baria AKA Cloud Boy..., If you have enjoyed and learned something useful, like this post, add a comment, and visit my Awesome SQL Interview GitHub repo.

Don't forget to give it a start šŸ˜….

Happy Coding šŸ§‘ā€šŸ’»

Top comments (2)

Collapse
 
jaiminbariya profile image
Jaimin Bariya

.

Collapse
 
prodevstaff profile image
ProDev. Staff