0% read
✦ Free Sample Lesson · 5 min read

Your First T-SQL Query

From zero to your first working query — using real mobile money transaction data from a Nigerian fintech. No jargon, no setup required.

📖 Week 1, Lesson 1
T-SQL Mastery Program
Instructor: Bibiane

What is T-SQL, and why does it matter in Africa?

T-SQL (Transact-SQL) is the language that runs inside Microsoft SQL Server — the database engine used by thousands of enterprises across Nigeria, Kenya, South Africa, Ghana, and beyond. Banks, telecoms, fintech platforms, healthcare systems, logistics companies: they all store their data in SQL Server, and they all need people who can query it.

When you know T-SQL, you can answer business questions directly from the data. No waiting for an engineer. No exporting to Excel. You open a query window, write a few lines, and the answer is right there.

This lesson covers the two most fundamental tools in that process: SELECT and WHERE.

Our dataset: PalmPay-style mobile money transactions

Imagine you're a junior data analyst at a Nigerian mobile money company — similar to PalmPay or OPay. The transactions team hands you access to a table called mobile_transactions. It looks like this:

transaction_id customer_id transaction_type amount_ngn status created_at state
TXN-10001C-4421transfer12500.00completed2025-01-15 09:42:11Lagos
TXN-10002C-7783airtime500.00completed2025-01-15 10:01:04Abuja
TXN-10003C-4421transfer75000.00failed2025-01-15 10:44:30Lagos
TXN-10004C-9102billpay8800.00completed2025-01-15 11:15:00Port Harcourt
TXN-10005C-3356transfer50000.00completed2025-01-15 11:58:44Kano
TXN-10006C-7783airtime200.00pending2025-01-15 12:30:19Abuja

Each row is one transaction. Your job: write queries to extract exactly the data the business needs.

Part 1 — SELECT: Choose your columns

Every T-SQL query starts with SELECT. It tells the database which columns you want back. The simplest possible query retrieves everything:

T-SQL Query 1 — Select all
SELECT *
FROM   mobile_transactions;

The * is a wildcard — it means "every column." This returns all 7 columns for every row in the table. In a real fintech database that might be millions of rows. You'd never run SELECT * in production. But it's fine to learn with.

More often, you'll name the columns you actually need:

T-SQL Query 2 — Select specific columns
SELECT transaction_id,
       customer_id,
       amount_ngn,
       status
FROM   mobile_transactions;

Why name specific columns? Two reasons. First, it's faster — the database doesn't retrieve data you don't need. Second, it's clearer — anyone reading your query immediately knows which fields matter for this analysis.

Part 2 — WHERE: Filter your rows

SELECT controls which columns you see. WHERE controls which rows you see. This is where T-SQL starts to feel powerful — instead of pulling the whole table, you can ask very specific business questions.

Example 1: Only completed transactions

The operations team wants a list of every transaction that went through successfully. You need rows where status = 'completed':

T-SQL Query 3 — Filter by status
SELECT transaction_id,
       customer_id,
       amount_ngn,
       status
FROM   mobile_transactions
WHERE  status = 'completed';

From our sample data, this returns 4 rows: TXN-10001, TXN-10002, TXN-10004, and TXN-10005. The failed and pending transactions are excluded.

Example 2: High-value transfers

The compliance team flags large transfers for review. Show them every completed transfer above ₦20,000:

T-SQL Query 4 — Multiple conditions with AND
SELECT transaction_id,
       customer_id,
       amount_ngn,
       state
FROM   mobile_transactions
WHERE  transaction_type = 'transfer'
  AND  status = 'completed'
  AND  amount_ngn > 20000;

Three conditions, all connected with AND. A row only appears if it satisfies all three. From our sample: only TXN-10005 (₦50,000 transfer from Kano, completed) passes all three filters.

AND vs OR: AND is more restrictive — every condition must be true. OR is more permissive — at least one condition must be true. Most business queries start with AND: you're looking for a specific subset, not a broad one.

Example 3: All transactions from Lagos or Abuja

The regional team wants data from two states. Use IN — it's cleaner than stacking OR conditions:

T-SQL Query 5 — IN operator
SELECT transaction_id,
       customer_id,
       amount_ngn,
       state,
       status
FROM   mobile_transactions
WHERE  state IN ('Lagos', 'Abuja');

This returns 4 rows: TXN-10001, TXN-10003 (Lagos), TXN-10002, TXN-10006 (Abuja). IN is the shorthand for state = 'Lagos' OR state = 'Abuja' — but much easier to read when you have 5+ values.

What you just learned

In one lesson, you can now:

This is Week 1 of 8 in the T-SQL Mastery program. By Week 4 you'll be writing joins, aggregations, and subqueries against real enterprise datasets. By Week 8, you'll have a portfolio project you can show in interviews.

🎯 Practice Challenge

Your turn — 3 queries to write

Using the mobile_transactions table above, try writing these queries on your own. Don't worry about running them yet — just write the SQL:

  1. 1 Select only the transaction_id, amount_ngn, and created_at columns for all rows where the transaction type is airtime.
  2. 2 Find all transactions for customer C-7783 that have a completed status.
  3. 3 List all failed or pending transactions (use IN), showing only transaction_id, status, and amount_ngn.

Hint for #3: WHERE status IN ('failed', 'pending')

Get 3 more free lessons →

Week 2 covers JOINs. Week 3 covers GROUP BY and aggregations. Week 4 covers window functions. All free, straight to your inbox.

Ready for the full 8-week program?

Live Saturday classes, real enterprise projects, 1-on-1 mentorship, and a portfolio you can show in interviews. Taught by a working data engineer with 8+ years of production T-SQL.

Enroll Now →

Classes start May 9, 2026 · Limited seats