Python Data Science Jobs & Interviews
20.4K subscribers
188 photos
4 videos
25 files
327 links
Your go-to hub for Python and Data Science—featuring questions, answers, quizzes, and interview tips to sharpen your skills and boost your career in the data-driven world.

Admin: @Hussein_Sheikho
Download Telegram
Top 100 SQL Interview Questions & Answers

#SQL #InterviewQuestions #DataAnalysis #Database #SQLQueries

👇👇👇👇👇
Please open Telegram to view this post
VIEW IN TELEGRAM
Top 100 SQL Interview Questions & Answers

#SQL #InterviewQuestions #DataAnalysis #Database #SQLQueries

Part 1: Basic Queries & DML/DDL (Q1-20)

#1. Select all columns and rows from a table named products.
A: Use SELECT * to retrieve all columns.

SELECT *
FROM products;

Output: All data from the 'products' table.


#2. Select only the product_name and price columns from the products table.
A: List the desired column names.

SELECT product_name, price
FROM products;

Output: A table with two columns: 'product_name' and 'price'.


#3. Find all products with a price greater than 50.
A: Use the WHERE clause with a comparison operator.

SELECT product_name, price
FROM products
WHERE price > 50;

Output: Products whose price is more than 50.


#4. Find all products that are red or have a price less than 20.
A: Use WHERE with OR to combine conditions.

SELECT product_name, color, price
FROM products
WHERE color = 'Red' OR price < 20;

Output: Products that are red OR cheaper than 20.


#5. Find all products that are red AND have a price greater than 100.
A: Use WHERE with AND to combine conditions.

SELECT product_name, color, price
FROM products
WHERE color = 'Red' AND price > 100;

Output: Products that are red AND more expensive than 100.


#6. Select all unique category values from the products table.
A: Use the DISTINCT keyword.

SELECT DISTINCT category
FROM products;

Output: A list of unique categories (e.g., 'Electronics', 'Books').


#7. Count the total number of products in the products table.
A: Use the COUNT(*) aggregate function.

SELECT COUNT(*) AS total_products
FROM products;

Output: A single number representing the total count.


#8. Find the average price of all products.
A: Use the AVG() aggregate function.

SELECT AVG(price) AS average_price
FROM products;

Output: A single number representing the average price.


#9. Find the highest and lowest price among all products.
A: Use the MAX() and MIN() aggregate functions.

SELECT MAX(price) AS highest_price, MIN(price) AS lowest_price
FROM products;

Output: Two numbers: the maximum and minimum price.


#10. Sort products by price in ascending order.
A: Use ORDER BY with ASC (or omit ASC as it's the default).

SELECT product_name, price
FROM products
ORDER BY price ASC;

Output: Products listed from cheapest to most expensive.


#11. Sort products by price in descending order.
A: Use ORDER BY with DESC.

SELECT product_name, price
FROM products
ORDER BY price DESC;

Output: Products listed from most expensive to cheapest.


#12. Sort products by category (ascending), then by price (descending).
A: Specify multiple columns in ORDER BY.

SELECT product_name, category, price
FROM products
ORDER BY category ASC, price DESC;

Output: Products grouped by category, then sorted by price within each category.