Pertanyaan dan Jawaban Wawancara Paling Populer & Tes Online
Platform edukasi untuk persiapan wawancara, tes online, tutorial, dan latihan langsung

Bangun keterampilan dengan jalur belajar terfokus, tes simulasi, dan konten siap wawancara.

WithoutBook menghadirkan pertanyaan wawancara per subjek, tes latihan online, tutorial, dan panduan perbandingan dalam satu ruang belajar yang responsif.

Prepare Interview

Ujian Simulasi

Jadikan Beranda

Bookmark halaman ini

Langganan Alamat Email
Beranda / Subjek Wawancara / SQL Query
WithoutBook LIVE Mock Interviews SQL Query Related interview subjects: 24

Interview Questions and Answers

Know the top SQL Query interview questions and answers for freshers and experienced candidates to prepare for job interviews.

Total 70 questions Interview Questions and Answers

The Best LIVE Mock Interview - You should go through before interview

Know the top SQL Query interview questions and answers for freshers and experienced candidates to prepare for job interviews.

Interview Questions and Answers

Search a question to view the answer.

Freshers / Beginner level questions & answers

Ques 7

What is a view in a database?

A view is a virtual table based on the result of a SELECT query, and it does not store the data itself.

Example:

CREATE VIEW view_name AS SELECT column1, column2 FROM table WHERE condition;
Simpan untuk Revisi

Simpan untuk Revisi

Bookmark item ini, tandai sebagai sulit, atau masukkan ke dalam set revisi.

Buka Perpustakaan Belajar Saya
Apakah ini membantu?
Add Comment View Comments
Ques 9

Explain the purpose of the ORDER BY clause.

The ORDER BY clause is used to sort the result set of a query in ascending or descending order based on one or more columns.

Example:

SELECT column1, column2 FROM table ORDER BY column1 DESC;
Simpan untuk Revisi

Simpan untuk Revisi

Bookmark item ini, tandai sebagai sulit, atau masukkan ke dalam set revisi.

Buka Perpustakaan Belajar Saya
Apakah ini membantu?
Add Comment View Comments
Ques 11

Explain the difference between CHAR and VARCHAR data types.

CHAR is a fixed-length string data type, while VARCHAR is a variable-length string data type. CHAR pads spaces to the maximum length, while VARCHAR only stores the actual data without padding.
Simpan untuk Revisi

Simpan untuk Revisi

Bookmark item ini, tandai sebagai sulit, atau masukkan ke dalam set revisi.

Buka Perpustakaan Belajar Saya
Apakah ini membantu?
Add Comment View Comments
Ques 12

What is the purpose of the SQL DISTINCT keyword?

The DISTINCT keyword is used to return unique values in the result set of a SELECT query by eliminating duplicate rows.

Example:

SELECT DISTINCT column FROM table;
Simpan untuk Revisi

Simpan untuk Revisi

Bookmark item ini, tandai sebagai sulit, atau masukkan ke dalam set revisi.

Buka Perpustakaan Belajar Saya
Apakah ini membantu?
Add Comment View Comments
Ques 13

What is the purpose of the SQL UPDATE statement?

The UPDATE statement is used to modify the existing records in a table by changing the values of one or more columns.

Example:

UPDATE table SET column1 = value1, column2 = value2 WHERE condition;
Simpan untuk Revisi

Simpan untuk Revisi

Bookmark item ini, tandai sebagai sulit, atau masukkan ke dalam set revisi.

Buka Perpustakaan Belajar Saya
Apakah ini membantu?
Add Comment View Comments
Ques 14

What is the purpose of the SQL LIKE operator?

The LIKE operator is used to search for a specified pattern in a column. It is often used with wildcard characters (% and _).

Example:

SELECT * FROM table WHERE column LIKE 'pattern%';
Simpan untuk Revisi

Simpan untuk Revisi

Bookmark item ini, tandai sebagai sulit, atau masukkan ke dalam set revisi.

Buka Perpustakaan Belajar Saya
Apakah ini membantu?
Add Comment View Comments

Intermediate / 1 to 5 years experienced level questions & answers

Ques 18

Explain INNER JOIN and LEFT JOIN.

INNER JOIN returns rows when there is a match in both tables. LEFT JOIN returns all rows from the left table and matching rows from the right table.

Example:

SELECT * FROM table1 INNER JOIN table2 ON table1.id = table2.id;
Simpan untuk Revisi

Simpan untuk Revisi

Bookmark item ini, tandai sebagai sulit, atau masukkan ke dalam set revisi.

Buka Perpustakaan Belajar Saya
Apakah ini membantu?
Add Comment View Comments
Ques 20

Explain the difference between UNION and UNION ALL.

UNION combines and returns unique rows from multiple SELECT statements, while UNION ALL returns all rows including duplicates.

Example:

SELECT column1 FROM table1 UNION SELECT column1 FROM table2;
Simpan untuk Revisi

Simpan untuk Revisi

Bookmark item ini, tandai sebagai sulit, atau masukkan ke dalam set revisi.

Buka Perpustakaan Belajar Saya
Apakah ini membantu?
Add Comment View Comments
Ques 21

Explain the difference between DELETE and TRUNCATE commands.

DELETE is used to remove rows from a table based on a condition. TRUNCATE removes all rows from a table without logging individual row deletions.

Example:

DELETE FROM table WHERE condition;
Simpan untuk Revisi

Simpan untuk Revisi

Bookmark item ini, tandai sebagai sulit, atau masukkan ke dalam set revisi.

Buka Perpustakaan Belajar Saya
Apakah ini membantu?
Add Comment View Comments
Ques 23

Explain the GROUP BY clause.

The GROUP BY clause is used in a SELECT statement to arrange identical data into groups, typically used with aggregate functions.

Example:

SELECT column, COUNT(*) FROM table GROUP BY column;
Simpan untuk Revisi

Simpan untuk Revisi

Bookmark item ini, tandai sebagai sulit, atau masukkan ke dalam set revisi.

Buka Perpustakaan Belajar Saya
Apakah ini membantu?
Add Comment View Comments
Ques 26

Explain the purpose of the HAVING clause.

The HAVING clause is used in combination with the GROUP BY clause to filter the results of aggregate functions based on specified conditions.

Example:

SELECT column, COUNT(*) FROM table GROUP BY column HAVING COUNT(*) > 1;
Simpan untuk Revisi

Simpan untuk Revisi

Bookmark item ini, tandai sebagai sulit, atau masukkan ke dalam set revisi.

Buka Perpustakaan Belajar Saya
Apakah ini membantu?
Add Comment View Comments
Ques 27

Explain the difference between a primary key and a unique key.

A primary key is used to uniquely identify each record in a table and cannot contain NULL values. A unique key enforces uniqueness but can contain NULL values.
Simpan untuk Revisi

Simpan untuk Revisi

Bookmark item ini, tandai sebagai sulit, atau masukkan ke dalam set revisi.

Buka Perpustakaan Belajar Saya
Apakah ini membantu?
Add Comment View Comments
Ques 28

Explain the difference between UNION and JOIN.

UNION is used to combine the results of two or more SELECT statements, while JOIN is used to retrieve data from multiple tables based on a related column between them.
Simpan untuk Revisi

Simpan untuk Revisi

Bookmark item ini, tandai sebagai sulit, atau masukkan ke dalam set revisi.

Buka Perpustakaan Belajar Saya
Apakah ini membantu?
Add Comment View Comments
Ques 30

What is a self-join?

A self-join is a regular join, but the table is joined with itself. It is useful when you want to combine rows with related data in the same table.

Example:

SELECT employee1.name, employee2.name FROM Employee employee1, Employee employee2 WHERE employee1.manager_id = employee2.employee_id;
Simpan untuk Revisi

Simpan untuk Revisi

Bookmark item ini, tandai sebagai sulit, atau masukkan ke dalam set revisi.

Buka Perpustakaan Belajar Saya
Apakah ini membantu?
Add Comment View Comments
Ques 32

What is the difference between a stored procedure and a function?

A stored procedure does not necessarily return a value, while a function must return a value. Functions can be used in SQL statements, whereas procedures cannot.
Simpan untuk Revisi

Simpan untuk Revisi

Bookmark item ini, tandai sebagai sulit, atau masukkan ke dalam set revisi.

Buka Perpustakaan Belajar Saya
Apakah ini membantu?
Add Comment View Comments
Ques 33

Explain the purpose of the SQL CASE statement.

The CASE statement is used to perform conditional logic within a SQL query, similar to an IF-THEN-ELSE statement in other programming languages.

Example:

SELECT column1, CASE WHEN condition THEN 'Result1' ELSE 'Result2' END AS NewColumn FROM table;
Simpan untuk Revisi

Simpan untuk Revisi

Bookmark item ini, tandai sebagai sulit, atau masukkan ke dalam set revisi.

Buka Perpustakaan Belajar Saya
Apakah ini membantu?
Add Comment View Comments
Ques 34

What is a subquery? Provide an example.

A subquery is a query embedded within another query. It can be used to retrieve data that will be used in the main query. Example: SELECT column FROM table WHERE column IN (SELECT column FROM another_table);
Simpan untuk Revisi

Simpan untuk Revisi

Bookmark item ini, tandai sebagai sulit, atau masukkan ke dalam set revisi.

Buka Perpustakaan Belajar Saya
Apakah ini membantu?
Add Comment View Comments
Ques 36

Explain the purpose of the SQL HAVING clause.

The HAVING clause is used to filter the results of aggregate functions in a SELECT statement based on specified conditions.

Example:

SELECT column, COUNT(*) FROM table GROUP BY column HAVING COUNT(*) > 1;
Simpan untuk Revisi

Simpan untuk Revisi

Bookmark item ini, tandai sebagai sulit, atau masukkan ke dalam set revisi.

Buka Perpustakaan Belajar Saya
Apakah ini membantu?
Add Comment View Comments
Ques 37

What is the difference between UNION and UNION ALL?

UNION combines and returns unique rows from multiple SELECT statements, while UNION ALL returns all rows including duplicates.

Example:

SELECT column1 FROM table1 UNION SELECT column1 FROM table2;
Simpan untuk Revisi

Simpan untuk Revisi

Bookmark item ini, tandai sebagai sulit, atau masukkan ke dalam set revisi.

Buka Perpustakaan Belajar Saya
Apakah ini membantu?
Add Comment View Comments
Ques 38

Explain the purpose of the SQL INDEX.

An INDEX is a performance optimization feature that allows faster retrieval of records from a table. It is created on one or more columns of a table.

Example:

CREATE INDEX index_name ON table(column);
Simpan untuk Revisi

Simpan untuk Revisi

Bookmark item ini, tandai sebagai sulit, atau masukkan ke dalam set revisi.

Buka Perpustakaan Belajar Saya
Apakah ini membantu?
Add Comment View Comments
Ques 42

Explain the difference between the INNER JOIN and OUTER JOIN.

INNER JOIN returns rows when there is a match in both tables, while OUTER JOIN returns all rows from one table and the matching rows from the other table, filling in the missing values with NULLs.

Example:

SELECT * FROM table1 INNER JOIN table2 ON table1.id = table2.id;
Simpan untuk Revisi

Simpan untuk Revisi

Bookmark item ini, tandai sebagai sulit, atau masukkan ke dalam set revisi.

Buka Perpustakaan Belajar Saya
Apakah ini membantu?
Add Comment View Comments
Ques 43

Explain the concept of a natural join.

A natural join is a type of JOIN that automatically matches columns with the same name in the joined tables. It eliminates duplicate columns in the result set.

Example:

SELECT * FROM table1 NATURAL JOIN table2;
Simpan untuk Revisi

Simpan untuk Revisi

Bookmark item ini, tandai sebagai sulit, atau masukkan ke dalam set revisi.

Buka Perpustakaan Belajar Saya
Apakah ini membantu?
Add Comment View Comments
Ques 44

Explain the concept of a CTE (Common Table Expression).

A CTE is a temporary result set that can be referenced within a SELECT, INSERT, UPDATE, or DELETE statement. It improves the readability and maintainability of complex queries.

Example:

WITH cte_name AS (SELECT * FROM table) SELECT * FROM cte_name;
Simpan untuk Revisi

Simpan untuk Revisi

Bookmark item ini, tandai sebagai sulit, atau masukkan ke dalam set revisi.

Buka Perpustakaan Belajar Saya
Apakah ini membantu?
Add Comment View Comments
Ques 45

Explain the purpose of the SQL GROUP_CONCAT() function.

The GROUP_CONCAT() function is used to concatenate values from multiple rows into a single string, grouped by a specified column.

Example:

SELECT department, GROUP_CONCAT(employee_name) FROM Employee GROUP BY department;
Simpan untuk Revisi

Simpan untuk Revisi

Bookmark item ini, tandai sebagai sulit, atau masukkan ke dalam set revisi.

Buka Perpustakaan Belajar Saya
Apakah ini membantu?
Add Comment View Comments
Ques 46

What is a common use case for the SQL COALESCE() function?

The COALESCE() function is used to return the first non-null expression among its arguments. A common use case is handling null values in a query.

Example:

SELECT COALESCE(column1, 'DefaultValue') FROM table;
Simpan untuk Revisi

Simpan untuk Revisi

Bookmark item ini, tandai sebagai sulit, atau masukkan ke dalam set revisi.

Buka Perpustakaan Belajar Saya
Apakah ini membantu?
Add Comment View Comments
Ques 47

Explain the purpose of the SQL SESSION_USER and SYSTEM_USER functions.

SESSION_USER returns the current username, and SYSTEM_USER returns the login name of the current user.

Example:

SELECT SESSION_USER, SYSTEM_USER;
Simpan untuk Revisi

Simpan untuk Revisi

Bookmark item ini, tandai sebagai sulit, atau masukkan ke dalam set revisi.

Buka Perpustakaan Belajar Saya
Apakah ini membantu?
Add Comment View Comments
Ques 48

What is the purpose of the SQL JSON functions (JSON_VALUE, JSON_QUERY, etc.)?

JSON functions in SQL are used to process JSON data. JSON_VALUE is used to extract a scalar value, and JSON_QUERY is used to extract an object or an array.

Example:

SELECT JSON_VALUE(json_column, '$.key') AS Value FROM table;
Simpan untuk Revisi

Simpan untuk Revisi

Bookmark item ini, tandai sebagai sulit, atau masukkan ke dalam set revisi.

Buka Perpustakaan Belajar Saya
Apakah ini membantu?
Add Comment View Comments
Ques 49

Explain the purpose of the SQL STRING_AGG() function.

The STRING_AGG() function is used to concatenate values from multiple rows into a single string with a specified separator.

Example:

SELECT department, STRING_AGG(employee_name, ', ') AS EmployeeList FROM Employee GROUP BY department;
Simpan untuk Revisi

Simpan untuk Revisi

Bookmark item ini, tandai sebagai sulit, atau masukkan ke dalam set revisi.

Buka Perpustakaan Belajar Saya
Apakah ini membantu?
Add Comment View Comments

Experienced / Expert level questions & answers

Ques 52

Write a SQL query to find the third highest salary from an Employee table.

SELECT MAX(salary) FROM Employee WHERE salary < (SELECT MAX(salary) FROM Employee WHERE salary < (SELECT MAX(salary) FROM Employee));
Simpan untuk Revisi

Simpan untuk Revisi

Bookmark item ini, tandai sebagai sulit, atau masukkan ke dalam set revisi.

Buka Perpustakaan Belajar Saya
Apakah ini membantu?
Add Comment View Comments
Ques 54

Write a SQL query to find the average salary of employees in each department, excluding departments with fewer than five employees.

SELECT department, AVG(salary) FROM Employee GROUP BY department HAVING COUNT(*) >= 5;
Simpan untuk Revisi

Simpan untuk Revisi

Bookmark item ini, tandai sebagai sulit, atau masukkan ke dalam set revisi.

Buka Perpustakaan Belajar Saya
Apakah ini membantu?
Add Comment View Comments
Ques 56

What is the purpose of the SQL TRIGGER?

A TRIGGER is a set of instructions that are automatically executed (or 'triggered') in response to specific events, such as INSERTs, UPDATEs, or DELETEs, on a particular table.

Example:

CREATE TRIGGER trigger_name BEFORE INSERT ON table FOR EACH ROW BEGIN -- trigger logic END;
Simpan untuk Revisi

Simpan untuk Revisi

Bookmark item ini, tandai sebagai sulit, atau masukkan ke dalam set revisi.

Buka Perpustakaan Belajar Saya
Apakah ini membantu?
Add Comment View Comments
Ques 57

Explain the purpose of the SQL ROLLUP operator.

The ROLLUP operator is used in conjunction with the GROUP BY clause to generate subtotals and grand totals for a set of columns in the result set.

Example:

SELECT department, city, SUM(salary) FROM Employee GROUP BY ROLLUP (department, city);
Simpan untuk Revisi

Simpan untuk Revisi

Bookmark item ini, tandai sebagai sulit, atau masukkan ke dalam set revisi.

Buka Perpustakaan Belajar Saya
Apakah ini membantu?
Add Comment View Comments
Ques 59

Explain the purpose of the SQL LEAD() and LAG() functions.

The LEAD() function is used to access the next row's data in the result set, while the LAG() function is used to access the previous row's data.

Example:

SELECT employee_name, salary, LEAD(salary) OVER (ORDER BY salary) AS NextSalary FROM Employee;
Simpan untuk Revisi

Simpan untuk Revisi

Bookmark item ini, tandai sebagai sulit, atau masukkan ke dalam set revisi.

Buka Perpustakaan Belajar Saya
Apakah ini membantu?
Add Comment View Comments
Ques 60

What is the purpose of the SQL CROSS APPLY operator?

The CROSS APPLY operator is used to invoke a table-valued function for each row returned by the outer query. It is similar to the INNER JOIN clause.

Example:

SELECT * FROM table1 CROSS APPLY function(table1.column) AS alias;
Simpan untuk Revisi

Simpan untuk Revisi

Bookmark item ini, tandai sebagai sulit, atau masukkan ke dalam set revisi.

Buka Perpustakaan Belajar Saya
Apakah ini membantu?
Add Comment View Comments
Ques 61

Write a SQL query to find the employees who have the highest salary in each department.

SELECT department, employee_name, salary FROM (SELECT department, employee_name, salary, ROW_NUMBER() OVER (PARTITION BY department ORDER BY salary DESC) AS rnk FROM Employee) AS ranked WHERE rnk = 1;
Simpan untuk Revisi

Simpan untuk Revisi

Bookmark item ini, tandai sebagai sulit, atau masukkan ke dalam set revisi.

Buka Perpustakaan Belajar Saya
Apakah ini membantu?
Add Comment View Comments
Ques 62

Explain the purpose of the SQL MERGE statement.

The MERGE statement is used to perform insert, update, or delete operations on a target table based on the results of a join with a source table. It is also known as an 'upsert' operation.

Example:

MERGE INTO target_table USING source_table ON condition WHEN MATCHED THEN UPDATE SET column1 = value1 WHEN NOT MATCHED THEN INSERT (column1, column2) VALUES (value1, value2);
Simpan untuk Revisi

Simpan untuk Revisi

Bookmark item ini, tandai sebagai sulit, atau masukkan ke dalam set revisi.

Buka Perpustakaan Belajar Saya
Apakah ini membantu?
Add Comment View Comments
Ques 63

What is the purpose of the SQL WINDOW functions?

WINDOW functions perform a calculation across a set of table rows related to the current row. They are used with the OVER() clause to define a window or a subset of rows for the calculation.

Example:

SELECT employee_name, salary, AVG(salary) OVER (PARTITION BY department) AS AvgSalary FROM Employee;
Simpan untuk Revisi

Simpan untuk Revisi

Bookmark item ini, tandai sebagai sulit, atau masukkan ke dalam set revisi.

Buka Perpustakaan Belajar Saya
Apakah ini membantu?
Add Comment View Comments
Ques 64

Write a SQL query to find the employees with the second-highest salary in each department.

SELECT department, employee_name, salary FROM (SELECT department, employee_name, salary, ROW_NUMBER() OVER (PARTITION BY department ORDER BY salary DESC) AS rnk FROM Employee) AS ranked WHERE rnk = 2;
Simpan untuk Revisi

Simpan untuk Revisi

Bookmark item ini, tandai sebagai sulit, atau masukkan ke dalam set revisi.

Buka Perpustakaan Belajar Saya
Apakah ini membantu?
Add Comment View Comments
Ques 65

Explain the purpose of the SQL XML functions (XMLAGG, XMLPARSE, XMLQUERY, etc.).

XML functions in SQL are used to process XML data. XMLAGG is used to concatenate XML values, XMLPARSE is used to convert a string to XML, and XMLQUERY is used to extract data from XML.
Simpan untuk Revisi

Simpan untuk Revisi

Bookmark item ini, tandai sebagai sulit, atau masukkan ke dalam set revisi.

Buka Perpustakaan Belajar Saya
Apakah ini membantu?
Add Comment View Comments
Ques 66

What is the purpose of the SQL PIVOT and UNPIVOT operators?

The PIVOT operator is used to rotate rows into columns, while the UNPIVOT operator is used to rotate columns into rows.

Example:

SELECT * FROM (SELECT department, salary FROM Employee) AS SourceTable PIVOT (SUM(salary) FOR department IN ([Dept1], [Dept2], [Dept3])) AS PivotTable;
Simpan untuk Revisi

Simpan untuk Revisi

Bookmark item ini, tandai sebagai sulit, atau masukkan ke dalam set revisi.

Buka Perpustakaan Belajar Saya
Apakah ini membantu?
Add Comment View Comments
Ques 68

Explain the purpose of the SQL ROW and RANGE clauses in window functions.

ROW and RANGE are used in the OVER() clause of window functions to define the window or subset of rows for the calculation. ROW refers to a physical count, while RANGE considers values within a specified range.
Simpan untuk Revisi

Simpan untuk Revisi

Bookmark item ini, tandai sebagai sulit, atau masukkan ke dalam set revisi.

Buka Perpustakaan Belajar Saya
Apakah ini membantu?
Add Comment View Comments
Ques 69

Write a SQL query to find the employees with the highest salary in each department using the DENSE_RANK() function.

SELECT department, employee_name, salary FROM (SELECT department, employee_name, salary, DENSE_RANK() OVER (PARTITION BY department ORDER BY salary DESC) AS rnk FROM Employee) AS ranked WHERE rnk = 1;
Simpan untuk Revisi

Simpan untuk Revisi

Bookmark item ini, tandai sebagai sulit, atau masukkan ke dalam set revisi.

Buka Perpustakaan Belajar Saya
Apakah ini membantu?
Add Comment View Comments
Ques 70

What is the purpose of the SQL TRY...CATCH statement?

The TRY...CATCH statement is used to handle errors in a SQL Server stored procedure. It allows for structured error handling and graceful error recovery.

Example:

BEGIN TRY -- SQL statements END TRY BEGIN CATCH -- Handling of errors END CATCH;
Simpan untuk Revisi

Simpan untuk Revisi

Bookmark item ini, tandai sebagai sulit, atau masukkan ke dalam set revisi.

Buka Perpustakaan Belajar Saya
Apakah ini membantu?
Add Comment View Comments

Most helpful rated by users:

Hak Cipta © 2026, WithoutBook.