I think you should use wp-api functions which will do everything for you.
- get_users() function will get all users data just define fields which u require.
- get_user_meta() function will get usermeta data.
$users = get_users( array( 'fields' => array( 'ID' ) ) );
foreach($users as $user){
print_r(get_user_meta ( $user->ID));
}