I have a case where, if I had written the DB and queries myself, I would just do something like
SELECT name, firstname, email FROM users WHERE .... Returning me a list/collection/array, I mean, not necessarily a single user.
But I learned that to get name and firstname in WordPress, you first need to get the IDs of some users, then use something like this
$targetUsers = get_users(['include' => wp_list_pluck($targetUsersIDs,'ID')]);
This means that I get a collection of complete user objects, which is potentially a lot of data for nothing.
For now, the best thing I come up with would be to run this query:
SELECT u.ID, u.user_email, um.meta_key, um.meta_value FROM wp_users u JOIN wp_usermeta um ON u.ID = um.user_id WHERE um.meta_key = 'last_name' OR um.meta_key = 'first_name' GROUP BY u.ID, u.user_email, um.meta_key, um.meta_key ORDER BY u.ID
and then loop over of it to build my own objects.
Or maybe there is something to do with some nested query...
Please note that the question is not about selecting specific fields from the user table but from the user meta table!