Jump to content

count() over to tables?


agge

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.