diff --git src/wp-includes/user.php src/wp-includes/user.php
index d02b022..3181921 100644
--- src/wp-includes/user.php
+++ src/wp-includes/user.php
@@ -857,7 +857,7 @@ function count_users($strategy = 'time') {
 		$select_count = implode(', ', $select_count);
 
 		// Add the meta_value index to the selection list, then run the query.
-		$row = $wpdb->get_row( "SELECT $select_count, COUNT(*) FROM $wpdb->usermeta WHERE meta_key = '{$blog_prefix}capabilities'", ARRAY_N );
+		$row = $wpdb->get_row( "SELECT $select_count, COUNT(*) FROM $wpdb->usermeta JOIN $wpdb->users ON user_id = ID WHERE meta_key = '{$blog_prefix}capabilities'", ARRAY_N );
 
 		// Run the previous loop again to associate results with role names.
 		$col = 0;
@@ -881,7 +881,7 @@ function count_users($strategy = 'time') {
 			'none' => 0,
 		);
 
-		$users_of_blog = $wpdb->get_col( "SELECT meta_value FROM $wpdb->usermeta WHERE meta_key = '{$blog_prefix}capabilities'" );
+		$users_of_blog = $wpdb->get_col( "SELECT meta_value FROM $wpdb->usermeta JOIN $wpdb->users ON user_id = ID WHERE meta_key = '{$blog_prefix}capabilities'" );
 
 		foreach ( $users_of_blog as $caps_meta ) {
 			$b_roles = maybe_unserialize($caps_meta);
diff --git tests/phpunit/tests/user/countUsers.php tests/phpunit/tests/user/countUsers.php
index d3192bb..b998d5e 100644
--- tests/phpunit/tests/user/countUsers.php
+++ tests/phpunit/tests/user/countUsers.php
@@ -186,4 +186,40 @@ class Tests_User_CountUsers extends WP_UnitTestCase {
 		);
 	}
 
+	/**
+	 * @ticket 29785
+	 */
+	public function test_should_not_count_users_who_are_not_in_posts_table_memory() {
+		global $wpdb;
+
+		// Get a 'before' count for comparison.
+		$count = count_users( 'memory' );
+
+		$u = self::factory()->user->create( array( 'role' => 'editor' ) );
+
+		// Manually delete the user, but leave the capabilities usermeta.
+		$wpdb->delete( $wpdb->users, array( 'ID' => $u ) );
+
+		$count2 = count_users( 'memory' );
+
+		$this->assertEqualSets( $count, $count2 );
+	}
+	/**
+	 * @ticket 29785
+	 */
+	public function test_should_not_count_users_who_are_not_in_posts_table_time() {
+		global $wpdb;
+
+		// Get a 'before' count for comparison.
+		$count = count_users( 'time' );
+
+		$u = self::factory()->user->create( array( 'role' => 'editor' ) );
+
+		// Manually delete the user, but leave the capabilities usermeta.
+		$wpdb->delete( $wpdb->users, array( 'ID' => $u ) );
+
+		$count2 = count_users( 'time' );
+
+		$this->assertEqualSets( $count, $count2 );
+	}
 }
