The two most common SQL statements within Koha application reports
This document will outline the two most common statements which appear in SQL reports run in the Koha application. SQL reports within the Koha application can only be run the return information that exists in the database, however, other SQL tools may allow the editing and updating of the underlying database. Editing and updating the underlying database is not possible from within the Koha reports tool.
The two statements required to structure an SQL report in Koha
SELECT
FROM
These two statements that will appear in almost every SQL report created on Koha. After the SELECT statement, there will be a list of the fields the report should display. After the FROM statement, there will be a list of the tables the information should be taken from.
SELECT
One of two mandatory statements that enable a report to work. This function defines the columns you want to draw information from. It should appear at the start of every report.
FROM
One of two mandatory functions to enable the report to work. FROM is the function that determines what the primary table the information requested with the SELECT function will be drawn from.
Example of how these statements are used in a report
SELECT borrowers.cardnumber, borrowers.firstname, borrowers.surname
FROM borrowers
| Version | Date | Detail | Author |
| 1.0 | 28/04/26 | Document created | Holly Cooper |
| 1.2 | 29/04/26 | Details added | Holly Cooper |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Related Articles
Overview of some SQL Report Functions
Overview of SQL Report Functions This FAQ is an example of a simple report describing the “anatomy” of the SQL code used. Details about the different functions are outlined in the table below the report. Some functions are mandatory to use in order ...
How to Find and Run a SQL Report
What are reports for? Reports are used to find and present data about the information on the system in a structured manner. Reports use SQL to ask questions of the Koha database. How to find reports on your system Go to the Reports module on the Koha ...
How to view the content of an SQL report
This document will outline how to view the content of an SQL report on the Koha system. This may be a precursor to editing the report or just a way to start studying the format of reports How to find reports on your system Go to the Reports module on ...
Question of the Week - Using the CASE statement and formatting information to be included in a SQL report
This document will outline how a list of information can be formatted so it can be easily added to a SQL statement as well as a creative way we used the CASE statement to categorise the different system preferences being shown in an SQL report. The ...
How to Report on Star Ratings on the OPAC
If star rating are enabled on the OPAC, staff members may wish to view details about how the feature is being used. This document will provide a basic SQL report which can be used to identify star ratings on the site. For information on how to enable ...