SQL for Accountants: Query Your Own Data
SQL is the language used to ask questions of a database. An accountant needs only five parts of it to be useful: SELECT to choose columns, FROM to name the table, WHERE to filter rows, GROUP BY to total them and JOIN to link tables. With those you can pull a customer ageing list or a monthly sales total straight from the source, rather than waiting for an export.
Why should an accountant learn SQL?
Much accounting data lives in databases: your accounting system, payroll, a shop's till system, an ERP. Reports from them are often fixed. SQL lets you ask a new question yourself, such as which invoices over €5,000 are more than 60 days overdue, without a developer. It is also readable and repeatable: a query is a written record of exactly how a number was produced, which helps if a reviewer or auditor asks. For other ways to use data well, see data analytics for finance.
Ask first whether you have permission and a safe way in. Use read-only access, or a copy of the data. Never run queries that change data on a live system until you are trained to do so.
What are the five building blocks?
SELECT and FROM
SELECT chooses columns and FROM chooses the table. SELECT invoice_no, customer, amount FROM invoices; returns those three columns for every row.
WHERE
WHERE filters. SELECT invoice_no, amount FROM invoices WHERE amount > 5000 AND status = 'Unpaid'; returns unpaid invoices over €5,000. Text goes in single quotes.
GROUP BY and totals
SELECT customer, SUM(amount) AS total FROM invoices GROUP BY customer; gives one row per customer with the total billed. COUNT, AVG, MIN and MAX work the same way. Add ORDER BY total DESC to put the biggest first. Filtering totals uses HAVING, for example HAVING SUM(amount) > 10000.
JOIN
A join links two tables on a shared key. SELECT c.name, SUM(i.amount) AS total FROM invoices i JOIN customers c ON i.customer_id = c.id GROUP BY c.name; returns customer names with totals, using the customers table to translate the ID. It is the database version of an Excel lookup.
Dates
Date functions differ between systems, so check your system's help. The idea is the same: filter with WHERE invoice_date >= '2026-01-01' and group by month.
Worked example: invoices at a Dublin practice
Orla's practice bills 300 clients. Her invoices table holds these rows for one afternoon's check:
- Client A: invoices of €1,200 and €800 (unpaid).
- Client B: invoices of €6,500 (unpaid).
- Client C: invoices of €900, €900 and €900 (paid).
She runs SELECT customer, SUM(amount) AS unpaid FROM invoices WHERE status = 'Unpaid' GROUP BY customer ORDER BY unpaid DESC; and gets Client B €6,500 and Client A €2,000. Total unpaid is €8,500. She checks it against the debtors figure on her trial balance. They agree, so the query is correct and she saves it as a named query for next month. Her partner then asks for the share owed by the single largest debtor: 6,500 / 8,500 = 76.5%. That is a fact she can put in front of him in a minute.
How do you stay safe and compliant?
- Read-only access. Ask for a login that can only SELECT.
- Personal data. Client names, bank details and payroll are personal data under GDPR. Select only the columns you need and keep results in controlled folders. See GDPR for small business.
- Test on small data. Add a limit on rows while you build a query.
- Reconcile. Compare totals to your ledger before you rely on any query.
- Beware duplicate rows from joins. If a customer appears twice in the customers table, a join doubles their invoices. Check row counts before and after.
How do you practise?
- Install a free database such as SQLite and load a month of your own anonymised sales from a CSV file.
- Write the five queries above on it.
- Rewrite a pivot table report as a query and compare the answers.
- Save queries with names and a note saying what question each answers.
- Move on to R or Python when you want to analyse the results further.
Key points
- SELECT, FROM, WHERE, GROUP BY and JOIN cover most accounting questions.
- A query is a repeatable record of how a number was produced.
- Use read-only access, limit personal data and reconcile every result.
- Practise on a copy of your own data.
Our Strategic Management programme shows you how to turn data like this into decisions about prices, clients and growth, so you do the analysis yourself.
Questions people ask
- Do accountants need to learn SQL?
- It is not essential, but it is very useful. SQL lets you pull exactly the data you need from accounting and business databases, check totals and answer new questions without waiting for a developer or a fixed report.
- What SQL commands should I learn first?
- Learn SELECT, FROM, WHERE, GROUP BY and JOIN. Together they let you choose columns, filter rows, total by group and link tables, which covers most accounting questions such as unpaid invoices by customer.
- Is it safe to run SQL on live accounting data?
- Only run SELECT queries on a read-only login or a copy of the data. Never run commands that change or delete data on a live system unless you are trained. Personal data must also be handled under GDPR.