What I want to do is select the count(*) of multiple tables I can't seem to get it quite right.
Code: Select all
SELECT count( * )
FROM `blog`
JOIN count( * )
FROM `gallery`
LIMIT 0 , 30How would I do more then 2 tables?
Thanks
Moderator: General Moderators
Code: Select all
SELECT count( * )
FROM `blog`
JOIN count( * )
FROM `gallery`
LIMIT 0 , 30Code: Select all
SELECT "e;blog"e;::VARCHAR(20) AS tablename,
count(*) FROM blog AS tablecount
UNION
SELECT "e;gallery"e;::VARCHAR(2) AS tablename,
count(*) FROM gallery AS tablecount;Code: Select all
$blogs=mysql_query("SELECT count(*) FROM `blogs`");
$users=mysql_query("SELECT count(*) FROM `users`");
$gallery=mysql_query("SELECT count(*) FROM `gallery` WHERE `approved` = 0 ");
$gallery_total=mysql_query("SELECT count(*) FROM `gallery`");Code: Select all
SELECT table_name, table_rows FROM INFORMATION_SCHEMA.TABLES
WHERE table_name IN('blogs','users','gallery');2 queries is still better then 4!! Thanks for the help.nielsene wrote:Doesn't help with the 'WHERE approved=0' one though....Code: Select all
SELECT table_name, table_rows FROM INFORMATION_SCHEMA.TABLES WHERE table_name IN('blogs','users','gallery');
Code: Select all
CREATE TABLE pending_actions (
tablename TEXT NOT NULL,
table_key TEXT NOT NULL,
pending_time TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (tablename, table_key)
);
-- some stored procedures to insert/delete rows into this table
-- on other table inserts/updates/deletes
SELECT tablename, count(table_key) FROM pending_actions GROUP BY tablename;