I have about six(6) tables each linked with userid. One of the tables is userinfo. The user info contains user details including their store platform(eg magento)
- Userinfo contains both active and non-active users (active users have created at least one activity in the other 5 tables).
- I want to count distinct number of users in the userinfo with platform of magento who have records in any of the other tables.
- Currently I am able to count distinct number of users in the other five tables with the ff code but want to join this with the userinfo table so I can select active users with platform magento.
- Without adding the userinfo table means I have no way of selecting users by platform.
-
Selecting users in userinfo table only, with platform of magento will be easy, but that means I may select users who only register but do not go on to create activity on my app.
$query3 = ("SELECT COUNT(*) FROM ( SELECT userid FROM table1 UNION SELECT userid FROM table2 UNION SELECT userid FROM table3 UNION SELECT userid FROM table4 UNION SELECT userid FROM table5 ) AS UserIDs"); $result3 = mysql_query($query3) or die(mysql_error()); $row3 = mysql_fetch_row($result3); echo "Number of distinct users in all tables = ".$row3[0] ."<br />"; **Table 1** Id userid name adresss **Table 2** Id Title Sex userid **Table 3** Id userid amount **Table 4** Id price promotion userid productid **Table 5** Id userid category tax weight **userinfo** Id userid username password platform