Users Pricing

forum

Home Forums mySQL union with calculated row – MindStick

mySQL union with calculated row

Dag Hammarskjold 3046 09 Jul 2013
Hi Expert!

I have a query similar to this:

select 'table_1', count(*)
from table_1
union 
select 'table_2', count(*)
from table_2
union 
select 'table_n', count(*)
from table_n
returning the total of rows for each table (n tables).

  table_1 | 100
  table_2 | 150
  table_n | 400
I want to know if there is a mysql function that can just add a new record at the end making the sum of all rows like this:

  table_1 | 100
  table_2 | 150
  table_n | 400
  total   | 650
Is there a way to do that in mySQL (version 5.5) whithout using a procedure? (for exemple using a variable inside the sql if supported)

Thanks in advance


1 Answers

Markdown for AI

A clean, structured version of this page for AI assistants and LLMs.

Open .md