SELECT, WHERE & ORDER BY · Question 18 · Hard

SELECT, WHERE & ORDER BY question 18

Table Payments:
txn_id | payer | app | amount | status
1 | Farhan | GPay | 250 | SUCCESS
2 | Lakshmi | PhonePe | 1200 | FAILED
3 | Farhan | Paytm | 800 | SUCCESS
4 | Gauri | GPay | 1200 | SUCCESS
5 | Lakshmi | GPay | 60 | SUCCESS
6 | Harish | PhonePe | 450 | PENDING
7 | Gauri | Paytm | 1200 | FAILED

No brackets are used in the WHERE clause. Which txn_id values are returned?

SELECT txn_id
FROM Payments
WHERE NOT status = 'SUCCESS'
   OR amount < 100 AND app = 'GPay'
ORDER BY txn_id;
  1. 2; 6; 7
  2. 5
  3. 2; 5; 6; 7
  4. 1; 3; 4; 5
Answer and explanation

Answer: C. 2; 5; 6; 7

Explanation: Precedence is NOT, then AND, then OR, so the condition is (status is not SUCCESS) OR (amount < 100 AND app = 'GPay'). The first part gives 2, 6 and 7; the second adds txn 5 (60 on GPay).

Previous: Table Students: roll | name | city | marks 1 | Aarav | Pune | 78 2 | Diya |… · Next: Table Students: roll | name | city | marks 1 | Aarav | Pune | 78 2 | Diya |…

Practise select, where & order by

Try a fresh set of select, where & order by questions with an explanation after every answer, free and without signing up: SELECT, WHERE & ORDER BY practice. Or sit a full placement mock test.

More select, where & order by questions

More sql practice

SQL Joins · Aggregates & GROUP BY · Subqueries & CTEs · Window Functions · NULL Handling · SQL Functions & CASE · UNION, INTERSECT & EXCEPT · Tables, Keys & Constraints

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge