I want to create a view from both the wp_users and wp_usermeta tables so that I can query rows in the view from an external application. Basic auth details are stored in wp_user
I found that Toote's solution works but is a performance hog on a MySQL database taking about 17 seconds to execute a "select * from users_with_meta_view".
I got this down to 0.0054 sec with a view structured like this instead:
CREATE OR REPLACE VIEW users_with_meta_view AS
SELECT
u.id,
u.user_login AS login,
u.user_pass AS password,
u.user_email AS email,
(select meta_value from wp_usermeta where user_id = u.id and meta_key = 'first_name' limit 1) as first_name,
(select meta_value from wp_usermeta where user_id = u.id and meta_key = 'last_name' limit 1) as last_name,
(select meta_value from wp_usermeta where user_id = u.id and meta_key = 'country' limit 1) as country
FROM wp_users u