SQL Real time interview questions and answers
SQL Real time interview questions and answers
Use Cases:
SELECT *
FROM emp1
WHERE employee_id NOT IN (SELECT employee_id FROM emp2);
Primary Key:
Foreign Key:
5. To find the customer who placed a specific order and the other customers
who have spent the most money
you would need two tables: customers and orders. Assuming the
customers table has columns customer_id and customer_name , and the
orders table has columns order_id, customer_id, and order_amount, you
can use the following SQL query:
This query first retrieves the customer name and order amount for the
specified order using the INNER JOIN between the customers and orders
tables. Then, it combines this result with the customer name and the
maximum order amount for the other orders. The result is sorted in
descending order based on the maximum order amount and limited to the
top 10 customers using the LIMIT keyword.
4. table find duplictes values sql query
5. rank vs denserank
Ans: The main difference is how they handle ties. RANK() can skip ranks in case of
ties, leaving gaps between rank values, while DENSE_RANK() does not skip ranks
for tied values.