sql - Why does COUNT(*) multiply the results when there are several tables? -


I have found:

  SELECT COUNT (*) to Table 1, Tab 2 , Table 3; Say that Tab 1 has 5 entries, Table 3 has 5 entries, and one in Tab 3, COUNT (*) is essentially 5 * 5 * 1 = 25. Is there any reason for this? Ideally, I want the total line number from all the 3 tables without using multiple from the statement   

  Select number (*) to Table 1, Tab 2, Tab 3;  

does a cross join . It corresponds to each record in TABLE1 from each record in TABLE2 , then matches the eash result with each record in TABLE3 For example if there were 4 records containing <3> record and TABLE4 in 2 records, TABLE2 in TABLE1 , you would have 2 x 3 x 4 = 24 was received> as your result.

You will need to use the subkey to calculate from each table:

  SELECT (SELECT COUNT (*) to TABLE1), (SELECT COUNT (* ) From tab 2), (tab number from selection number (*) 3); TABLE1 union from all SELECT COUNT (*) to tab2 union ALL SELECTED COUNT (*) to TABLE3  

OR

  SELECT COUNT (*)  

to get the result as a record instead of columns

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -