MySQL社区
标题:
请教关系表之间查询的问题
[打印本页]
作者:
a36148614
时间:
2016-8-30 10:21
标题:
请教关系表之间查询的问题
现有两个关系表
表一
user_ID user_name user_type
表二
user_type_id type
现在需要查询得到这样的一张视图
表三
user_ID user_name type
请大神指教如何得到?
作者:
yflower
时间:
2016-8-31 15:24
你的表一种user_type字段是表二的user_type_id字段吧,如果是,就这样写:
select t1.user_id,t1.user_name,t2.type
from table1 t1 inner join table2 t2 on t1.user_type=t2.user_type_id;
参考自:
mysql join用法详解
http://www.data.5helpyou.com/article209.html
欢迎光临 MySQL社区 (http://www.mysqlpub.com/)
Powered by Discuz! X3.2