![]() |
Fast select count
Hi guys .. i have a trouble i want to select count(id) FROM 5 tables and choose the quicker way...
I tried something like SELECT (SELECT (COUNT(id)) AS likes FROM status_likes WHERE nick='Trki') as likes_count, (SELECT (COUNT(id)) AS comments FROM comments WHERE nick='Trki') as comments_count, (SELECT (COUNT(id)) AS statuses FROM statuses WHERE nick='Trki') as statuses_count which works good but isn't it as slow as i would make 5mysql queries separetly with SELECT ? OR is there some better way? :P THX! +++ ANOTHER PROBLEM This query SELECT DISTINCT shared_from_id FROM statuses WHERE shared_from_id<>0 returns this: shared_from_id 3481 3455 3423 3388 3386 3362 3272 3117 What is good.. and why then i cant use the all query like this ? :( : SELECT nick FROM statuses WHERE id IN (SELECT DISTINCT shared_from_id FROM statuses WHERE shared_from_id<>0) The program died or show the result with duration more then 31s :/ :( IF someone would help i would be glad :) |
Quote:
Code:
SELECT s1.nickCode:
SELECT s1.nickMight be a good idea to add an index on shared_from_id. p.s. You don't even need the "WHERE" clause, unless you want to exclude the row where id = 0. But it shouldn't matter too much. |
Quote:
nick;id Paulis1992;3362 george12;3272 jdawg91;3388 Horin;3386 Horin;3386 Horin;3386 Horin;3386 Horin;3386 Horin;3386 Horin;3386 domin47;3423 masuronike;3117 masuronike;3481 george12;3455 but also this: nick;shared_from_id george12;3362 Gianniluke;3272 rdy2win;3388 martinaltman;3386 Trki;3386 masuronike;3386 C1zk0;3386 pLAYERsvk;3386 JoHnnn;3386 MACHi;3386 Out92;3423 czechpete;3117 Strupik;3481 Strupik;3455 which is SELECT nick,shared_from_id FROM statuses WHERE shared_from_id<>0 ... the people who shared...ideas ? :P |
| All times are GMT +1. The time now is 04:21 PM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.