Skip to main content

Essential Koha SQL Reports: Librarian Circulation Tracking, Item Type Inventory & Cataloguing Status

In Koha Integrated Library System (ILS), standard circulation and cataloguing reports often miss key operational details—such as which staff member processed a check-in/checkout, or a unified view of item status, acquisition source, subject, and department. Below are production-tested, institution-agnostic SQL reports that any library can use directly in Koha → Reports → Create from SQL.

1. Date-Wise Check-in Report with Staff ID & Librarian Name

In Koha's action_logs table, RETURN transactions store the patron's borrowernumber in object and the returned itemnumber in info. Matching on both within a short timestamp window reliably identifies the staff member who processed the check-in.

SELECT
    DATE_FORMAT(s.datetime, '%d %b %Y %h:%i %p') AS Return_Date,
    DATE_FORMAT(s.datetime, '%d %b %Y') AS Date,
    i.barcode AS Barcode,
    b.title AS Title,
    b.author AS Author,
    p.cardnumber AS Card_No,
    p.firstname AS First_Name,
    p.surname AS Last_Name,
    COALESCE(staff.cardnumber, '-') AS Staff_ID,
    COALESCE(CONCAT_WS(' ', staff.firstname, staff.surname), 'System/Self') AS Librarian
FROM statistics s
LEFT JOIN items i ON i.itemnumber = s.itemnumber
LEFT JOIN biblio b ON b.biblionumber = i.biblionumber
LEFT JOIN borrowers p ON p.borrowernumber = s.borrowernumber
LEFT JOIN borrowers staff ON staff.borrowernumber = (
    SELECT al.user
    FROM action_logs al
    WHERE al.module = 'CIRCULATION'
      AND al.action = 'RETURN'
      AND (al.info = CAST(s.itemnumber AS CHAR) OR al.object = s.borrowernumber)
      AND al.timestamp BETWEEN s.datetime - INTERVAL 10 SECOND AND s.datetime + INTERVAL 10 SECOND
    ORDER BY ABS(TIMESTAMPDIFF(SECOND, al.timestamp, s.datetime)), al.action_id DESC
    LIMIT 1
)
WHERE s.type = 'return'
  AND s.datetime >= <<From Date|date>>
  AND s.datetime < DATE_ADD(<<To Date|date>>, INTERVAL 1 DAY)
ORDER BY s.datetime DESC, i.barcode ASC

2. Date-Wise Checkout Report with Staff ID & Librarian Name

For ISSUE transactions, action_logs.object records the patron's borrowernumber. Joining against statistics gives an accurate daily or date-range checkout log with the issuing librarian.

SELECT 
    DATE_FORMAT(c.datetime, '%d %b %Y %h:%i %p') AS Issue_Date, 
    i.barcode AS Barcode, 
    b.title AS Title, 
    b.author AS Author, 
    p.cardnumber AS Card_No, 
    p.firstname AS First_Name, 
    p.surname AS Last_Name,
    COALESCE(staff.cardnumber, '-') AS Staff_ID,
    COALESCE(CONCAT_WS(' ', staff.firstname, staff.surname), 'System/Self') AS Librarian
FROM statistics c 
LEFT JOIN items i ON (c.itemnumber = i.itemnumber) 
LEFT JOIN borrowers p ON (c.borrowernumber = p.borrowernumber) 
LEFT JOIN biblio b ON (i.biblionumber = b.biblionumber)
LEFT JOIN borrowers staff ON staff.borrowernumber = (
    SELECT al.user
    FROM action_logs al
    WHERE al.module = 'CIRCULATION'
      AND al.action = 'ISSUE'
      AND al.object = c.borrowernumber
      AND al.timestamp BETWEEN c.datetime - INTERVAL 10 SECOND AND c.datetime + INTERVAL 10 SECOND
    ORDER BY ABS(TIMESTAMPDIFF(SECOND, al.timestamp, c.datetime)), al.action_id DESC
    LIMIT 1
)
WHERE DATE(c.datetime) BETWEEN <<From Date|date>> AND <<To Date|date>>
  AND c.type = 'issue' 
ORDER BY c.datetime DESC, i.barcode ASC

3. Total Collection Report with Item Type & Department Filter

This inventory report filters by Koha's itemtypes dropdown (with automatic fallback from items.itype to biblioitems.itemtype) and optionally filters by Department stored in MARC 526$a (enter % for all departments).

SELECT 
    biblio.title AS Title,
    biblio.subtitle AS Subtitle,
    biblio.author AS Author,
    biblio.copyrightdate AS Year,
    biblioitems.publishercode AS Publisher,
    biblioitems.editionstatement AS Edition,
    itemtypes.description AS Item_Type,
    ExtractValue(biblio_metadata.metadata, '//datafield[@tag="526"]/subfield[@code="a"]') AS Department,
    items.itemcallnumber AS Call_Number,
    items.price AS Price,
    items.copynumber AS Copy_Number,
    items.barcode AS Barcode 
FROM items 
LEFT JOIN biblioitems ON (items.biblioitemnumber = biblioitems.biblioitemnumber) 
LEFT JOIN biblio ON (biblioitems.biblionumber = biblio.biblionumber) 
LEFT JOIN biblio_metadata ON (biblio.biblionumber = biblio_metadata.biblionumber)
LEFT JOIN branches ON (branches.branchcode = items.holdingbranch)
LEFT JOIN itemtypes ON (itemtypes.itemtype = IFNULL(items.itype, biblioitems.itemtype))
WHERE (items.itype = <<Select Item Type|itemtypes>> OR (items.itype IS NULL AND biblioitems.itemtype = <<Select Item Type|itemtypes>>))
  AND ExtractValue(biblio_metadata.metadata, '//datafield[@tag="526"]/subfield[@code="a"]') LIKE CONCAT('%', <<Department (or % for all)>>, '%')
ORDER BY biblio.title ASC

4. Cataloguing Report by Date (with Subject, Department, Source & Live Status)

Ideal for monthly or periodic cataloguing audits, this report includes the accession date, subject (650$a), department (526$a), acquisition source (items.booksellerid), live circulation status, and the cataloguer who added the item.

SELECT 
    DATE_FORMAT(i.dateaccessioned, '%d %b %Y') AS Accession_Date, 
    i.barcode AS Barcode, 
    TRIM(BOTH '/' FROM TRIM(
        CONCAT_WS(' : ', 
            b.title, 
            NULLIF(ExtractValue(bm.metadata, '//datafield[@tag="245"]/subfield[@code="b"]'), '')
        )
    )) AS Title, 
    b.author AS Author, 
    ExtractValue(bm.metadata, '//datafield[@tag="250"]/subfield[@code="a"]') AS Edition,
    ExtractValue(bm.metadata, '//datafield[@tag="260"]/subfield[@code="c"]') AS Year,
    ExtractValue(bm.metadata, '//datafield[@tag="650"]/subfield[@code="a"]') AS Subject,
    ExtractValue(bm.metadata, '//datafield[@tag="526"]/subfield[@code="a"]') AS Department,
    COALESCE(i.booksellerid, '') AS Source,
    CASE
        WHEN i.withdrawn != 0 THEN 'Withdrawn'
        WHEN i.itemlost != 0 THEN 'Lost'
        WHEN i.damaged != 0 THEN 'Damaged'
        WHEN iss.issue_id IS NOT NULL THEN 'Checked Out'
        WHEN i.notforloan != 0 THEN 'Not for Loan'
        ELSE 'Available'
    END AS Status,
    i.price AS Price,
    i.itemcallnumber AS Call_Number, 
    i.homebranch AS Branch,
    bor.borrowernumber AS Cataloguer_ID,
    CONCAT(bor.firstname, ' ', bor.surname, ' (', bor.cardnumber, ')') AS Cataloguer
FROM items i 
LEFT JOIN biblio b ON (i.biblionumber = b.biblionumber)
LEFT JOIN biblioitems bib ON (i.biblioitemnumber = bib.biblioitemnumber)
LEFT JOIN biblio_metadata bm ON (b.biblionumber = bm.biblionumber)
LEFT JOIN issues iss ON (iss.itemnumber = i.itemnumber)
LEFT JOIN action_logs al ON (al.object = i.itemnumber AND al.module = 'CATALOGUING' AND al.action = 'ADD')
LEFT JOIN borrowers bor ON (al.user = bor.borrowernumber)
WHERE DATE(i.dateaccessioned) BETWEEN <<Accessioned between (yyyy-mm-dd)|date>> AND <<and (yyyy-mm-dd)|date>>
ORDER BY i.dateaccessioned DESC

Need help customizing Koha ILS reports, OPAC themes, or server automation for your institution? Contact Sothik IT.

How to Run These Reports in Koha

  1. Log in to the Koha Staff Interface with a user account that has Reports permissions.
  2. Go to Reports → Guided reports → Create from SQL (or Reports → Create from SQL).
  3. Enter a Report name and optionally select a Report group (e.g., Circulation or Catalog).
  4. Paste any of the SQL queries above into the SQL box and click Save report.
  5. Click Run report and fill in the prompted filters (e.g., From Date / To Date, Select Item Type, or Department — enter % for all departments).
  6. Click Run the report to view results in the browser, or click Download to export as CSV / Excel.

Comments

Popular posts from this blog