Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
4 views

PostgresSQL Server

The document consists of a series of questions and answers related to SQL concepts, including the purpose of various SQL clauses, functions, and commands. Key topics covered include GROUP BY, ORDER BY, primary and foreign keys, SQL JOIN types, and aggregate functions. The document serves as a quiz or study guide for understanding fundamental SQL operations and terminology.

Uploaded by

saksham.kumar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

PostgresSQL Server

The document consists of a series of questions and answers related to SQL concepts, including the purpose of various SQL clauses, functions, and commands. Key topics covered include GROUP BY, ORDER BY, primary and foreign keys, SQL JOIN types, and aggregate functions. The document serves as a quiz or study guide for understanding fundamental SQL operations and terminology.

Uploaded by

saksham.kumar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

PostgresSQL Server:

What is the purpose of the GROUP BY clause in SQL?

a) To filter rows based on a condition

b) To sort the result set in ascending order

c) To group rows based on a column and perform aggregate functions

d) To join two or more tables

Answer: c) To group rows based on a column and perform aggregate functions

Which SQL function is used to find the highest value in a column?

a) MIN()

b) AVG()

c) MAX()

d) SUM()

Answer: c) MAX()

What is the purpose of the ORDER BY clause in SQL?

a) To filter rows based on a condition

b) To sort the result set in ascending or descending order

c) To group rows based on a column and perform aggregate functions

d) To join two or more tables

Answer: b) To sort the result set in ascending or descending order

In SQL, what is a primary key?

a) A key used to encrypt data in a table

b) A column or combination of columns that uniquely identifies each row in a table

c) A key used to establish a relationship between two tables

d) A key used to sort data in a table

Answer: b) A column or combination of columns that uniquely identifies each row in a table
Which SQL command is used to make permanent changes to the database?

a) COMMIT

b) ROLLBACK

c) SAVEPOINT

d) APPLY

Answer: a) COMMIT

What is a foreign key in SQL?

a) A key used to encrypt data in a table

b) A key used to establish a relationship between two tables

c) A column or combination of columns that uniquely identifies each row in a table

d) A key used to sort data in a table

Answer: b) A key used to establish a relationship between two tables

Which SQL JOIN type returns all rows from both tables and fills in NULL values for non-matching
rows?

a) INNER JOIN

b) LEFT JOIN (or LEFT OUTER JOIN)

c) RIGHT JOIN (or RIGHT OUTER JOIN)

d) FULL JOIN (or FULL OUTER JOIN)

Answer: d) FULL JOIN (or FULL OUTER JOIN)

What is the purpose of the SQL function COUNT()?

a) To find the average value in a column

b) To count the total number of rows in a table

c) To find the sum of values in a column

d) To find the highest value in a column

Answer: b) To count the total number of rows in a table

Which SQL statement is used to update existing data in a database table?

a) UPDATE
b) INSERT

c) MODIFY

d) SET

Answer: a) UPDATE

What is the purpose of the SQL function GROUP_CONCAT()?

a) To concatenate values from multiple rows into a single string

b) To calculate the average value in a column

c) To find the maximum value in a column

d) To calculate the total sum of values in a column

Answer: a) To concatenate values from multiple rows into a single string

Which SQL statement is used to delete data from a database table?

a) DELETE

b) TRUNCATE

c) DROP

d) REMOVE

Answer: a) DELETE

In SQL, what is the purpose of the HAVING clause?

a) To filter rows based on a condition

b) To sort the result set in ascending or descending order

c) To group rows based on a column and perform aggregate functions

d) To filter rows based on aggregate function results

Answer: d) To filter rows based on aggregate function results

What is a subquery in SQL?

a) A query used to retrieve data from a single table only

b) A query used to retrieve data from multiple tables using joins

c) A query used as an input to another query's condition or filter

d) A query used to delete data from a table


Answer: c) A query used as an input to another query's condition or filter

Which SQL function is used to calculate the average value in a column?

a) MIN()

b) MAX()

c) AVG()

d) SUM()

Answer: c) AVG()

What is the purpose of the SQL CASE statement?

a) To filter rows based on a condition

b) To sort the result set in ascending or descending order

c) To group rows based on a column and perform aggregate functions

d) To perform conditional logic and return different values based on specified conditions

Answer: d) To perform conditional logic and return different values based on specified conditions

Which SQL statement is used to create a new database table?

a) CREATE TABLE

b) INSERT INTO

c) ALTER TABLE

d) MAKE TABLE

Answer: a) CREATE TABLE

Which SQL query is used to retrieve data from multiple tables?

a) SELECT INTO

b) JOIN

c) GROUP BY

d) UNION

Answer: b) JOIN
What is the purpose of the SQL ORDER BY clause?

a) To filter rows based on a condition

b) To sort the result set in ascending or descending order

c) To group rows based on a column and perform aggregate functions

d) To join two or more tables

Answer: b) To sort the result set in ascending or descending order

Which SQL query is used to add a new column to an existing table?

a) ADD COLUMN

b) ALTER TABLE

c) CREATE COLUMN

d) INSERT COLUMN

Answer: b) ALTER TABLE

What does the SQL HAVING clause do?

a) Filters rows based on a condition

b) Joins two or more tables

c) Groups rows based on a column and performs aggregate functions

d) Filters rows based on aggregate function results

Answer: d) Filters rows based on aggregate function results

Which SQL query is used to delete a table from the database?

a) DROP

b) DELETE

c) REMOVE

d) ERASE

Answer: a) DROP

What is the purpose of the SQL GROUP BY clause?

a) To filter rows based on a condition

b) To sort the result set in ascending or descending order


c) To group rows based on a column and perform aggregate functions

d) To join two or more tables

Answer: c) To group rows based on a column and perform aggregate functions

Which SQL query is used to update data in a table with values from another table?

a) REPLACE

b) INSERT INTO

c) UPDATE JOIN

d) UPDATE SET

Answer: d) UPDATE SET

What is the purpose of the SQL DISTINCT keyword?

a) To filter rows based on a condition

b) To sort the result set in ascending or descending order

c) To remove duplicates from the result set

d) To join two or more tables

Answer: c) To remove duplicates from the result set

Which SQL query is used to combine the results of two or more SELECT queries and remove
duplicates?

a) INTERSECT

b) UNION

c) JOIN

d) MERGE

Answer: b) UNION

What is the purpose of the SQL LIMIT clause?

a) To filter rows based on a condition

b) To sort the result set in ascending or descending order

c) To limit the number of rows returned in the result set

d) To join two or more tables


Answer: c) To limit the number of rows returned in the result set

Which SQL query is used to find the nth highest salary in a table?

a) SELECT TOP N Salary FROM Employees ORDER BY Salary DESC;

b) SELECT Salary FROM Employees ORDER BY Salary DESC LIMIT N,1;

c) SELECT MAX(Salary) FROM Employees WHERE Salary NOT IN (SELECT MAX(Salary) FROM
Employees);

d) SELECT Salary FROM Employees ORDER BY Salary DESC LIMIT N-1,1;

Answer: d) SELECT Salary FROM Employees ORDER BY Salary DESC LIMIT N-1,1;

What is the purpose of the SQL ROW_NUMBER() function?

a) To assign a unique identifier to each row in the result set.

b) To calculate the average value of a column in the result set.

c) To filter rows based on specific conditions.

d) To join two or more tables based on a common column.

Answer: a) To assign a unique identifier to each row in the result set.

Which SQL query is used to find employees who have the same salary as the highest-paid employee?

a) SELECT * FROM Employees WHERE Salary = MAX(Salary);

b) SELECT * FROM Employees WHERE Salary = (SELECT MAX(Salary) FROM Employees);

c) SELECT * FROM Employees HAVING Salary = MAX(Salary);

d) SELECT * FROM Employees GROUP BY Salary HAVING Salary = MAX(Salary);

Answer: b) SELECT * FROM Employees WHERE Salary = (SELECT MAX(Salary) FROM Employees);

What is the purpose of the SQL COALESCE() function?

a) To combine the results of two or more SELECT queries.

b) To filter rows based on specific conditions.

c) To convert data types from one to another.

d) To return the first non-null value in a list of expressions.

Answer: d) To return the first non-null value in a list of expressions.


Which SQL query is used to find the employees who joined before their manager?

a) SELECT * FROM Employees e WHERE e.JoinDate < (SELECT JoinDate FROM Employees WHERE
ManagerID = e.ManagerID);

b) SELECT * FROM Employees WHERE JoinDate < Manager.JoinDate;

c) SELECT * FROM Employees WHERE JoinDate < ALL (SELECT JoinDate FROM Employees WHERE
ManagerID = e.ManagerID);

d) SELECT * FROM Employees e WHERE e.JoinDate < ANY (SELECT JoinDate FROM Employees WHERE
ManagerID = e.ManagerID);

Answer: a) SELECT * FROM Employees e WHERE e.JoinDate < (SELECT JoinDate FROM Employees
WHERE ManagerID = e.ManagerID);

What is the purpose of the SQL CROSS JOIN?

a) To combine rows from two or more tables based on a related column.

b) To return the Cartesian product of two or more tables.

c) To combine rows from two or more tables based on a specified condition.

d) To join two or more tables and return only the matching rows.

Answer: b) To return the Cartesian product of two or more tables.

Which SQL query is used to find the most recent record for each employee in the "Logs" table?

a) SELECT DISTINCT ON (EmployeeID) * FROM Logs ORDER BY EmployeeID, LogDate DESC;

b) SELECT * FROM Logs WHERE LogDate = MAX(LogDate) GROUP BY EmployeeID;

c) SELECT * FROM Logs GROUP BY EmployeeID HAVING LogDate = MAX(LogDate);

d) SELECT * FROM Logs WHERE LogDate = (SELECT MAX(LogDate) FROM Logs WHERE EmployeeID =
Logs.EmployeeID);

Answer: a) SELECT DISTINCT ON (EmployeeID) * FROM Logs ORDER BY EmployeeID, LogDate DESC;

What is the purpose of the SQL LEAD() window function?

a) To return the next row relative to the current row within a result set.

b) To calculate the cumulative sum of a column in the result set.

c) To find the difference between the current row and the next row in a result set.

d) To assign a rank to each row based on the values of a specific column.

Answer: a) To return the next row relative to the current row within a result set.
Which SQL query is used to find the number of occurrences of each value in a column?

a) SELECT Column, COUNT(*) FROM Table;

b) SELECT Column, COUNT(Column) FROM Table GROUP BY Column;

c) SELECT Column, COUNT(1) FROM Table GROUP BY Column;

d) SELECT COUNT(Column) FROM Table;

Answer: b) SELECT Column, COUNT(Column) FROM Table GROUP BY Column;

What is the purpose of the SQL WINDOW clause?

a) To define the ordering of rows within a result set.

b) To specify the condition for filtering rows.

c) To combine rows from two or more tables based on a related column.

d) To define a window for performing calculations using window functions.

Answer: d) To define a window for performing calculations using window functions.

What does SQL stand for?

a) Structured Query Language

b) Sequential Query Language

c) System Query Language

d) Standard Query Language

Answer: a) Structured Query Language

Which SQL keyword is used to retrieve data from a database table?

a) SELECT

b) UPDATE

c) DELETE

d) INSERT

Answer: a) SELECT

In SQL, which clause is used to filter rows based on specific criteria?

a) ORDER BY

b) GROUP BY
c) WHERE

d) HAVING

Answer: c) WHERE

Which SQL statement is used to insert new data into a database table?

a) UPDATE

b) INSERT

c) MODIFY

d) ADD

Answer: b) INSERT

You might also like