SQL Test 5

    Question 1NULL vs 0 Distinction

    What is the difference between NULL and 0?

    Question 2AUTO_INCREMENT and IDENTITY

    What is AUTO_INCREMENT/IDENTITY and which data types support it?

    Question 3INSERT Methods and Syntax

    What are the different ways to use INSERT command?

    Question 4GROUP BY with NULL Values

    How does GROUP BY handle NULL values?

    Question 5ORDER BY with SELECT

    How does ORDER BY work with SELECT statement?

    Question 6When to Drop or Rebuild Indexes

    When should indexes be dropped or rebuilt?

    Question 7Combining Multiple Operators

    How can multiple SQL operators be combined effectively?

    Question 8INNER JOIN with WHERE Clause

    Can WHERE clause be used with INNER JOIN?

    Question 9OUTER JOIN Use Cases

    When should OUTER JOINs be used instead of INNER JOINs?

    Question 10Ignoring NULL in Aggregates

    How do aggregate functions handle NULL values?

    Question 11Counting Rows

    Which query counts the total number of students in the students table?

    Question 12Mixed Data Type Conversion

    In an employees table with columns (emp_id INT, salary DECIMAL(10,2), hire_date DATE, is_active BOOLEAN), write a query to show employee ID and years of service for active employees hired before 2020.

    Question 13Conditional Deletion and Table Removal

    Delete all products with zero stock quantity from products table, then completely remove the temp_backup table from the database.

    Question 14Basic GROUP BY with Aggregate Functions

    From an orders table (order_id, customer_id, order_date, total_amount), find the total sales amount and number of orders for each customer.

    Question 15SELECT with IN Operator and Column Aliases

    From a products table (product_id, product_name, category, price, stock_quantity), select product_name as 'Product', price as 'Cost' for products in categories 'Electronics', 'Books', or 'Clothing' where stock is greater than 0.

    Question 16When an Index is Ignored

    You have an index on the last_name column of the customers table. Why might the following query not use that index?
    SELECT * FROM customers WHERE UPPER(last_name) = 'SMITH';

    Question 17Combined Operators with NOT and Complex Logic

    From a orders table (order_id, customer_id, order_date, status, total_amount), find orders that are NOT in status 'Cancelled' or 'Refunded', have total amount between $50 and $200, and customer_id is NOT in the list (101, 102, 103).

    Question 18INNER JOIN with Aggregate Functions

    Using the orders (order_id, customer_id, total_amount) and customers (customer_id, country) tables, find the total sales amount for each country.

    Question 19Filtering Outer Joins

    Using a LEFT OUTER JOIN between customers and orders, you want to find only those customers who have not placed any orders.

    Question 20Combining Aggregates in One Query

    Which query shows the minimum and maximum salary from the employees table?