mvdw310 Posted January 22, 2023 Share Posted January 22, 2023 Dear all, I want to count rows from a table with the info from a other table Table 1: id = 22 + published = 1 id = 23 + published = 0 id = 24 + published = 1 id = 25 + published = 1 Table 2: id = 22 + Car = A id = 23 + Car = B id = 24 + Car = C id = 25 + Car = A Result : Car A = 2 Car B = 0 Car C = 1 who can help me with some code to come to a solution to do this. Grtz Manfred Quote Link to comment https://forums.phpfreaks.com/topic/315826-count-rows-from-one-table-with-the-info-from-a-other-table/ Share on other sites More sharing options...
Barand Posted January 22, 2023 Share Posted January 22, 2023 mysql> select * from table1; +----+-----------+ | id | published | +----+-----------+ | 22 | 1 | | 23 | 0 | | 24 | 1 | | 25 | 1 | +----+-----------+ 4 rows in set (0.00 sec) mysql> select * from table2; +----+------+ | id | car | +----+------+ | 22 | A | | 23 | B | | 24 | C | | 25 | A | +----+------+ 4 rows in set (0.03 sec) mysql> SELECT car -> , sum(published) as tot -> FROM table1 -> JOIN table2 USING (id) -> GROUP BY car; +------+------+ | car | tot | +------+------+ | A | 2 | | B | 0 | | C | 1 | +------+------+ 3 rows in set (0.00 sec) Quote Link to comment https://forums.phpfreaks.com/topic/315826-count-rows-from-one-table-with-the-info-from-a-other-table/#findComment-1604903 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.