Q1
True / FalseIn PostgreSQL, the SQL execution order starts with the SELECT clause.
The SQL execution order starts with the FROM clause, followed by WHERE, GROUP BY, HAVING, SELECT, and then ORDER BY.
Q2
True / FalseThe FROM clause is executed before the WHERE clause in PostgreSQL.
The FROM clause is indeed the first to be executed, as it determines the data source for the query. The WHERE clause is applied afterward to filter the rows.
Q3
True / FalseIn PostgreSQL, the ORDER BY clause is executed before the SELECT clause.
The ORDER BY clause is executed after the SELECT clause. The SELECT clause specifies which columns to return, and the ORDER BY clause determines the order of the returned rows.
Q4
True / FalseThe GROUP BY clause in PostgreSQL is executed after the WHERE clause but before the SELECT clause.
The GROUP BY clause groups the rows after they have been filtered by the WHERE clause and before the SELECT clause determines the columns to return.
Q5
True / FalseIn PostgreSQL, the HAVING clause is executed before the GROUP BY clause.
The HAVING clause is executed after the GROUP BY clause. It filters groups based on aggregate functions.
Q6
True / FalseThe LIMIT clause in PostgreSQL is applied after the ORDER BY clause.
The LIMIT clause restricts the number of rows returned and is applied after the rows have been ordered by the ORDER BY clause.
Q7
True / FalseIn PostgreSQL, window functions are executed after the WHERE clause but before the ORDER BY clause
Window functions are executed after the ORDER BY clause. They are applied to the result set of the query before any final output is returned.
Q8
True / FalseThe execution of CTEs (Common Table Expressions) in PostgreSQL occurs before the main query execution starts.
CTEs are executed before the main query and their result is used in the subsequent execution steps of the main query.
Q9
True / FalseIn PostgreSQL, the DISTINCT keyword is applied after the SELECT clause but before the ORDER BY clause.
The DISTINCT keyword removes duplicate rows after the SELECT clause has determined the columns to return but before the rows are ordered by the ORDER BY clause.
Q10
True / FalseIn PostgreSQL, the SQL execution order of a query with JOIN, WHERE, and GROUP BY clauses is JOIN -> WHERE -> GROUP BY.
The JOIN operation is performed first to combine tables, followed by the WHERE clause to filter rows, and finally, the GROUP BY clause to group the filtered rows.
Q21
Multiple ChoiceWhich SQL query correctly demonstrates the execution order in PostgreSQL?
SQL Code
SELECT department, COUNT(*)
FROM employees
WHERE salary > 50000
GROUP BY department
HAVING COUNT(*) > 5
ORDER BY department;
In PostgreSQL, the SQL execution order typically follows the sequence: FROM -> WHERE -> GROUP BY -> HAVING -> SELECT -> ORDER BY.
Q22
Multiple ChoiceIn which order does PostgreSQL execute the following query?
SQL Code
SELECT name, AVG(salary)
FROM employees
GROUP BY name
HAVING AVG(salary) > 60000
ORDER BY name;
The correct order of execution for this query is: FROM -> GROUP BY -> HAVING -> SELECT -> ORDER BY.
Q23
Multiple ChoiceWhich SQL execution order is correct for filtering, grouping, and sorting data in PostgreSQL?
SQL Code
SELECT region, SUM(total_sales)
FROM sales
WHERE total_sales > 1000
GROUP BY region
ORDER BY SUM(total_sales) DESC;
The SQL execution order is: FROM -> WHERE -> GROUP BY -> SELECT -> ORDER BY.
Q24
Multiple ChoiceWhich SQL execution order is applied when aggregating and sorting data in PostgreSQL?
SQL Code
SELECT customer_id, SUM(order_total)
FROM orders
GROUP BY customer_id
ORDER BY SUM(order_total) DESC;
The execution order in this case is: FROM -> GROUP BY -> SELECT -> ORDER BY.
Q25
Multiple ChoiceHow does PostgreSQL execute a query involving JOIN, WHERE, and ORDER BY clauses?
SQL Code
SELECT e.name, d.department_name
FROM employees e
JOIN departments d ON e.department_id = d.department_id
WHERE e.salary > 70000
ORDER BY e.name;
The correct order is: FROM (including JOIN) -> WHERE -> SELECT -> ORDER BY.
Q26
Multiple ChoiceWhat is the correct execution order for a complex SQL query in PostgreSQL?
SQL Code
SELECT department, COUNT(*) AS employee_count
FROM employees
WHERE hire_date > '2020-01-01'
GROUP BY department
HAVING COUNT(*) > 10
ORDER BY employee_count DESC;
The execution order is: FROM -> WHERE -> GROUP BY -> HAVING -> SELECT -> ORDER BY.
Q27
Multiple ChoiceHow does PostgreSQL execute a query with multiple aggregate functions and conditions?
SQL Code
SELECT department, AVG(salary), COUNT(*)
FROM employees
WHERE department IN ('Sales', 'Engineering')
GROUP BY department
HAVING AVG(salary) > 60000
ORDER BY COUNT(*) DESC;
The order of execution is: FROM -> WHERE -> GROUP BY -> HAVING -> SELECT -> ORDER BY.
Q28
Multiple ChoiceIn which order does PostgreSQL process a subquery within a SELECT statement?
SQL Code
SELECT name, (SELECT AVG(salary) FROM employees WHERE department = 'Engineering') AS avg_salary
FROM employees
WHERE department = 'Engineering';
Subqueries are processed first, followed by the outer query: FROM -> WHERE -> SELECT (including subquery).
Q29
Multiple ChoiceWhich execution order is followed by PostgreSQL for nested queries?
SQL Code
SELECT employee_id, (SELECT COUNT(*) FROM orders WHERE employee_id = e.employee_id) AS total_orders
FROM employees e
WHERE department = 'Sales';
Nested queries are executed first, followed by the outer query: FROM (outer query) -> SELECT (subquery) -> WHERE (outer query).
Q30
Multiple ChoiceHow does PostgreSQL execute a complex query with multiple joins and conditions?
SQL Code
SELECT e.name, d.department_name, SUM(o.order_total)
FROM employees e
JOIN departments d ON e.department_id = d.department_id
JOIN orders o ON e.employee_id = o.employee_id
WHERE o.order_date > '2023-01-01'
GROUP BY e.name, d.department_name
HAVING SUM(o.order_total) > 10000
ORDER BY e.name;
The execution order is: FROM (including JOINs) -> WHERE -> GROUP BY -> HAVING -> SELECT -> ORDER BY.