se le tabelle sono correlate da tutto il campo è possibile utilizzare l'alias di tabelle come
select count(*) from table1 tb1, table2 tb2, table3 tb3 where
tb1.field1 = tb2.field2 and tb2.field2 = tb3.field3
similario,
delete from table1 tb1, table2 tb2, table3 tb3 where
tb1.field1 = tb2.field2 and tb2.field2 = tb3.field3
è possibile includere le condizioni secondo i requisiti dell'utente.
Se le tabelle non hanno alcuna relazione quindi utilizzare sotto
SELECT
(SELECT COUNT(*) FROM table1 WHERE someCondition) as count1,
(SELECT COUNT(*) FROM table2 WHERE someCondition) as count2,
(SELECT COUNT(*) FROM table3 WHERE someCondition) as count3
è possibile rimuovere la clausola in cui se non ci sono le condizioni.
USCITA:
| count1 | count2 | count3 |
| 50 | 36 | 21 |
fonte
2011-12-06 11:08:47
ah .. grazie. Il preparare stmt da @str è molto utile. – scravy
La procedura aggiornata è molto utile. Sembra che 'db_name' non abbia effetto su nulla con la configurazione corrente (l'ho rimosso completamente senza problemi nella procedura). – DACrosby
Bello. Per mostrare il conteggio individuale delle voci in ogni tabella:
select table_name,table_rows from information_schema.tables where table_schema = 'your_db_name'
– gaoithe