简体   繁体   中英

How to join 2 values from different tables in mysql

I'm a beginner in MySQL, so I need help. I want to get values of name column from table role to show it together with information from users instead id_role . How can I realize it? What should the query I write? Can you attach the link with solve?

The picture for explanation. 点击查看

Read more here about SQL JOINS

SELECT users.*, role.*
FROM users
INNER JOIN role ON users.id_role = role.id;

尝试左加入

SELECT `users`.*,`role`.name as role FROM `users` LEFT JOIN `role` ON `users`.id_role= `role`.id

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