C
C
chelovek_rediska2017-01-07 01:56:47
MySQL
chelovek_rediska, 2017-01-07 01:56:47

How to fix incorrect row count in MySQL?

There are several tables with a total of 12 rows
5901ced7bd5a416f9bf1f3109eb08711.PNG
. To get the number, I created a procedure:

BEGIN
SELECT sum(cnt) as 'Всего записей' from ( 
        select count(*) as cnt from xx
  UNION select count(*) as cnt from visa 
  UNION select count(*) as cnt from xvii
  UNION select count(*) as cnt from xviii 
  UNION select count(*) as cnt from xix 
  UNION select count(*) as cnt from states
  UNION select count(*) as cnt from xxi) as t;
END

Without the info table, there should be 11 rows in total, but the procedure only outputs the value 7. All tables have the same fields

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2017-01-07
@chelovek_rediska

UNION is executed as DISTINCT by default, that is, only unique rows will be in the resulting table, instead of three twos, only one will be included. Replace UNION with UNION ALL.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question