Home > Back-end >  Display a fixed set of terms at the end of each report created through SQL query
Display a fixed set of terms at the end of each report created through SQL query

Time:09-15

So I have a task to create a report that displays some data, for which I have a working query. The next challenge is that every time I run the query, it should also print certain terms with the report. The terms are in the form of the table itself but I have restricted access to the database. I cannot update the table with new data.

What I want to achieve here is:

|-------------|
|Report data  |
|-------------|
|Fixed Set of terms|
|------------------|

I am looking for a way to append some text at the end of the table. Not sure how can I do that, hoping for some help.

CodePudding user response:

SELECT
  x, y, z
FROM
  foo

UNION ALL

SELECT
  'SOMETHING', 1, 5

UNION ALL

SELECT
  'ANYTHING', 2, 7

ORDER BY
  x, y, z

The data types being unioned should match, don't try to union integers with strings, for example.

The ORDER BY is applied after the UNIONs.

UNION normally searches for and removes duplicates. Specifying UNION ALL avoids that costly overhead.

  • Related