0% found this document useful (0 votes)
5 views6 pages

SQL Question

The document provides a comprehensive guide on SQL queries, covering various topics such as SELECT statements, WHERE clauses, ORDER BY, GROUP BY, JOINs, and subqueries. It includes examples for retrieving records, filtering data, counting transactions, and identifying duplicates. Additionally, it offers tips for debugging transaction issues and specific SQL questions relevant for interviews.

Uploaded by

Darshan Gabhane
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views6 pages

SQL Question

The document provides a comprehensive guide on SQL queries, covering various topics such as SELECT statements, WHERE clauses, ORDER BY, GROUP BY, JOINs, and subqueries. It includes examples for retrieving records, filtering data, counting transactions, and identifying duplicates. Additionally, it offers tips for debugging transaction issues and specific SQL questions relevant for interviews.

Uploaded by

Darshan Gabhane
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

1.

SELECT basics

How do you retrieve all records from a table named transactions?

sql

CopyEdit

SELECT * FROM transactions;

2. WHERE clause

How do you find all failed transactions?

sql

CopyEdit

SELECT * FROM transactions WHERE status = 'FAILED';

Find all users from Mumbai?

sql

CopyEdit

SELECT * FROM customers WHERE city = 'Mumbai';

3. ORDER BY & LIMIT

How do you find the latest 5 transactions of an account?

sql

CopyEdit

SELECT * FROM transactions

WHERE account_id = '1234567890'

ORDER BY transaction_date DESC

LIMIT 5;

4. GROUP BY & COUNT

How many transactions has each account made?


sql

CopyEdit

SELECT account_id, COUNT(*) AS txn_count

FROM transactions

GROUP BY account_id;

Top 5 accounts with the most transactions?

sql

CopyEdit

SELECT account_id, COUNT(*) AS txn_count

FROM transactions

GROUP BY account_id

ORDER BY txn_count DESC

LIMIT 5;

5. DATE filtering

Find failed transactions that happened today?

sql

CopyEdit

SELECT * FROM transactions

WHERE status = 'FAILED'

AND DATE(transaction_date) = CURDATE();

6. JOINs (basic level)

List customer names with their account balances?

sql

CopyEdit

SELECT c.name, a.balance

FROM customers c
JOIN accounts a ON c.customer_id = a.customer_id;

7. UPDATE (read-only use case in interviews)

How to change the city of a customer?

sql

CopyEdit

UPDATE customers

SET city = 'Pune'

WHERE customer_id = 'C1023';

They usually won’t let you update data directly in L1/L2 — this is just to check your
syntax knowledge.

8. Find Duplicates

How to find duplicate mobile numbers in customers table?

sql

CopyEdit

SELECT mobile_number, COUNT(*)

FROM customers

GROUP BY mobile_number

HAVING COUNT(*) > 1;

9. Subqueries

Find accounts with balance more than average?

sql

CopyEdit

SELECT *

FROM accounts

WHERE balance > (SELECT AVG(balance) FROM accounts);


10. NULL checks

Find customers without email ID?

sql

CopyEdit

SELECT * FROM customers WHERE email IS NULL;

Tip for Interview

If they ask:

“How do you debug a transaction issue?”

You can say:

“I check the transaction ID in the database using SELECT, check the status, timestamp, and
error codes if any. Then I check logs using tail -f or grep if needed.”

SQL Questions for Your Role

1. Get customer details whose account balance is below ₹1000 (low balance warning).

sql

CopyEdit

SELECT * FROM customers

WHERE balance < 1000;

2. Find the top 5 accounts with the highest number of transactions.

sql

CopyEdit

SELECT account_id, COUNT(*) AS txn_count

FROM transactions

GROUP BY account_id

ORDER BY txn_count DESC


LIMIT 5;

3. Retrieve the last 10 transactions made by a customer with account number


'1234567890'.

sql

CopyEdit

SELECT * FROM transactions

WHERE account_id = '1234567890'

ORDER BY transaction_date DESC

LIMIT 10;

4. Count the number of failed transactions today.

sql

CopyEdit

SELECT COUNT(*) AS failed_count

FROM transactions

WHERE status = 'FAILED'

AND DATE(transaction_date) = CURDATE();

7. Show number of transactions grouped by status (e.g., SUCCESS, FAILED, PENDING).

sql

CopyEdit

SELECT status, COUNT(*) AS count

FROM transactions

GROUP BY status;

8. Get customer names who have more than one account.

sql

CopyEdit
SELECT customer_id, COUNT(*) AS total_accounts

FROM accounts

GROUP BY customer_id

HAVING COUNT(*) > 1;

9. A user claims a transaction was done on ‘2025-07-01’ but it’s not showing. How would
you find it?

sql

CopyEdit

SELECT * FROM transactions

WHERE account_id = '1234567890'

AND DATE(transaction_date) = '2025-07-01';

10. Get list of customers whose names start with 'S'.

sql

CopyEdit

SELECT * FROM customers

WHERE name LIKE 'S%';

You might also like