Skip to content

Most items $2 · Packs priced separately

pocketshelf

HR and Payroll SQL: Data Cleanup Queries

sql-cleanup-queries-for-hr-and-payroll.pdfShowing 18 of 72 lines
// Find duplicate work_email
SELECT work_email, count(*)
FROM employees
GROUP BY work_email
HAVING count(*) > 1;

// Delete duplicates, keep the newest
DELETE FROM employees
WHERE id IN (
  SELECT id FROM (
    SELECT id, row_number() OVER (PARTITION BY lower(work_email) ORDER BY id DESC) AS rn
    FROM employees
  ) t
  WHERE rn > 1
);

// Trim stray whitespace
UPDATE employees

What's inside

  • HR and Payroll SQL: Data Cleanup Queries, preview page 1 with code examples in two columnsPage 1
  • HR and Payroll SQL: Data Cleanup Queries, preview page 2 with code examples in two columnsPage 2
Format
PDF, Markdown, SQL
Contents
12 queries
Version
1.0 · Updated 3 Oct 2026
Licence
Commercial What this means
Checked
Checked before it ships
Files in your download
  • sql-cleanup-queries-for-hr-and-payroll.pdfPDF · 21 KB
  • sql-cleanup-queries-for-hr-and-payroll.mdMarkdown · 2 KB
  • sql-cleanup-queries-for-hr-and-payroll.sqlSQL · 2 KB
  • LICENSE.txtadded to every download

About this item

A compact, printable snippet pack for data cleanup and maintenance queries for an HR and payroll database (employees and timesheets). Each of the 12 entries has a one-line explanation and a small example you can paste into your editor. The PDF uses a two-column A4 layout designed to sit next to your keyboard, and the same content ships as Markdown so you can search it or drop it into your notes, plus a .sql file with every query. Every SQL example targets PostgreSQL 16.

  • SQL
  • HR and payroll
  • Cleanup
  • PostgreSQL
  • Snippets

You might also grab