Practice SQL Questions and Answers
- Which of the following is not a type of SQL JOIN?
- What is the difference between DELETE, TRUNCATE, and DROP commands in SQL?
- In SQL, what is the difference between 'WHERE' and 'HAVING' clauses?
- In database management, which SQL command is used to retrieve only unique (non-duplicate) values from a column?
- What will be the output of the following SQL query? SELECT COUNT(*) FROM Transactions WHERE Amount > 10000 AND Status = 'Completed';
- What is a 'stored procedure' in SQL?
- Which query returns departments whose average salary is greater than 60000?
- Which SQL expression correctly returns employees whose salary is greater than the average salary of all employees?
- Orders(OrderID, CustomerID, Amount) has multiple orders per customer. Which query returns customers whose total order amount exceeds 100000?
- Table T has five rows and X values (10,20,NULL,20,NULL). What does SELECT COUNT(X) FROM T return?
- Given Employee(EmpID, Name, Salary, ManagerID), which query correctly lists employees who earn more than their own manager?
- Table B contains a NULL value in its 'id' column. Consider: SELECT * FROM A WHERE A.id NOT IN (SELECT id FROM B). What happens?
- A table has salaries 90000, 90000, 85000, 80000 (sorted descending). Using RANK() OVER (ORDER BY Salary DESC), what ranks are assigned, and how does this d...
- A table has a B-tree index on the 'Name' column. Which of the following queries is LEAST likely to benefit from this index?
- Transaction T1 runs 'SELECT COUNT(*) FROM Orders WHERE Amount > 1000' twice within the same transaction. Between the two reads, T2 inserts a new qualifying...
- Employees(emp_id, name, salary, mgr_id): (1,'Alice',9000,NULL), (2,'Bob',7000,1), (3,'Carol',9500,1), (4,'Dave',6000,2). What does the following self-join ...
- Customers(cust_id,name): (1,'A'),(2,'B'),(3,'C'). Orders(order_id,cust_id,amount): (1,1,200),(2,2,150),(3,1,300),(4,3,100). What does the following query r...
- Employees and salaries: Alice=9000, Bob=7000, Carol=9500, Dave=7000. What rank does Dave receive from the following query? SELECT name, salary, RANK() OVER...
- Table T(A,B) contains: (1,NULL), (NULL,2), (3,4), (NULL,NULL). How many rows are returned by the following query? SELECT * FROM T WHERE A=3 OR B=4;
- A view is defined as: CREATE VIEW V AS SELECT dept_id, AVG(salary) AS avg_sal FROM Employees GROUP BY dept_id; Can this view be used directly in an UPDATE ...
- Consider two tables: Employees(EmpID, Name, DeptID) with 8 rows, and Departments(DeptID, DeptName) with 3 rows. Every employee has exactly one valid DeptID...
- Table Students(StudentID, Marks) contains the marks: 45, 67, 89, 72, 90, 55, 78. What will the following query return? SELECT COUNT(*) FROM Students WHERE ...
- Table Orders(OrderID, CustomerID) has 10 rows with CustomerID values: C1, C1, C2, C3, C1, C2, C4, C2, C3, C1. How many groups (customers) will be returned ...
- Table Employee(EmpID, ManagerID) has 6 rows: (1,NULL), (2,1), (3,1), (4,2), (5,2), (6,3). How many rows will the following self-join return? SELECT E.EmpID...
- Consider the table Employees(EmpID, Name, Dept, Salary). What will the following SQL query return? SELECT Dept, COUNT(*) FROM Employees GROUP BY Dept HAVIN...
- A column named Salary in a table contains the values 50000, NULL, 60000, and 70000. What value will the SQL expression AVG(Salary) return for this column?
- For the table Employees(EmpID, Name, Dept, Salary), which SQL query correctly retrieves all employees who earn more than the average salary of their own de...
- Which SQL statement is used to add a new column to an existing table?
- Β Which SQL aggregate function returns the total number of rows matching a specified condition?
- Which type of SQL join returns only those rows that have matching values present in both of the joined tables, excluding any unmatched rows from either sid...
- Which SQL command permanently removes both the stored data and the entire structural definition (columns, constraints, indexes) of a table from the databas...
- A table T has exactly 10 rows. Its column X contains 3 NULL values among its 10 entries, and of the remaining 7 non-null values, exactly two are duplicates...
- Table A has 5 rows and Table B has 4 rows. Exactly 3 rows in A each match exactly one row in B under a given join condition (the remaining 2 rows in A have...
- Which type of SQL join returns all rows from the left table along with matching rows from the right table, filling in NULLs for the right table's columns w...
- Which SQL command removes all rows from a table very quickly (typically without generating per-row log entries) while preserving the table's structure, and...
- Which SQL aggregate function returns the number of rows in a column that contain a non-NULL value, ignoring NULL entries in that column?
- A 'view' in SQL is best described as:
- Which single SQL constraint, when applied to a column, automatically enforces both uniqueness of values and a NOT NULL restriction, and is also used to uni...
- Which type of SQL subquery references one or more columns from its outer (enclosing) query, and as a result must be logically re-evaluated once for every r...
- Which type of SQL JOIN returns only the rows that have matching values in both of the joined tables?
More Topics
- Algorithms Questions
- Analog and Digital Communication Questions
- Artificial Intelligence & Machine Language Questions
- Basics of Computers Questions
- Big Data Analytics Questions
- C Programming Questions
- C++ Questions
- Cloud Computing Questions
- Compiler Design Questions
- Computer Architecture and Design Questions
- Cyber Security Questions
- Data Analytics Languages Questions
- Data Structure Questions
- Data Warehousing Questions
- Digital Logic Questions
- Emerging Technologies Questions
- IOT and mobile Computing Questions
- IT DBMS Questions
- IT Networking Questions
- IT Operating System Questions
- Java Language Questions
- Machine Learning Questions
- Memory Management Questions
- Microsoft Office Questions
- Miscellaneous Questions Questions
- Network Layer and IP Protocol Questions
- Numerical and Statistical Computing Questions
- Object Oriented Programming Questions
- OOPS Concepts Questions
- Previous Year Questions Questions
- Programming Concept Questions
- Python Questions
- Shell Scripting Questions
- Software Engineering and Web Technology Questions
- String Manipulation Questions
- TCP IP and OSI Questions