agge Posted March 19, 2007 Share Posted March 19, 2007 I have an db with two tables wich I have some values in and I want to count this rows from with an select. I tb_1 tb_2 ID1 num 1 ID1 num 2 ID2 num 1 ID1 num 2 ID3 num 1 - ID3 num 1 ID4 num 2 ID5 num 1 - ID5 num 1 ID7 num 1 $query = SELECT COUNT(ID) AS num FROM tb_1 WHERE num = 1; -- I get 4 rows $query = SELECT COUNT(ID) AS num FROM tb_2 WHERE num = 1; -- I get 3 rows And if I sum this up I get 7 rows wich is correct, but if I want to GROUP BY ID and only count the DISTINCT ID from this two tables so I only get 5 rows where ID 3 and ID 5 in tb_2 is counting from the tb_1 Anyone who knows how I'm going to do with this? Link to comment https://forums.phpfreaks.com/topic/43336-count-over-to-tables/ Share on other sites More sharing options...
Cep Posted March 19, 2007 Share Posted March 19, 2007 You would just edit your where clause to be ID = 3 and then use the same formula you have above. Why would you need to use GROUP BY? Am I missing something? Link to comment https://forums.phpfreaks.com/topic/43336-count-over-to-tables/#findComment-210421 Share on other sites More sharing options...
agge Posted March 19, 2007 Author Share Posted March 19, 2007 You would just edit your where clause to be ID = 3 and then use the same formula you have above. Why would you need to use GROUP BY? Am I missing something? Sorry I missed to change ID to num so I count rows with num = 1, if you look now the select fomula is different now. Link to comment https://forums.phpfreaks.com/topic/43336-count-over-to-tables/#findComment-210424 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.