简体   繁体   中英

mysql inner join on two tables

Columns in table wp_users :

id
user_login

Columns in table wp_usermeta :

 user_id
 meta_key [if equals 'primaryblog']
 metav_value

The id in wp_users and the user-id in wp_usermeta are same. I am expecting the result as

id, user_login, meta_key, meta_value

I tried:

select a.user_id,a.meta_key,a.meta_value 
from wp_usermeta as a 
where meta_key = 'primaryblog' 
inner join b.id, b.user_login 
from wp_users as b on a.user_id=b.id

How to get the intended result?

The JOIN comes before the WHERE clause:

SELECT 
  a.id, a.user_login, b.meta_key, b.meta_value
FROM wp_users a
JOIN wp_usermeta b ON a.id = b.user_id
WHERE meta_key = 'primaryblog';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM