需要与表格进行比较并显示一行数据而不是其他 [英] Need to compare to tables and show one rows data in place of other

查看:39
本文介绍了需要与表格进行比较并显示一行数据而不是其他的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,可以说它在我拥有的 users_chars 表中看起来像这样

Ok lets say it looks like this in table users_chars i have

pos_zone
255

表二

zone_id | name
 255    | This_Area

我将如何比较它们并显示名称行而不是 id

how would i go about comparing them and showing the name row instead of the id

推荐答案

select t.name
from users_chars uc
inner join table_two t on uc.pos_zone = t.zone_id

这是什么意思:

select t.name 告诉数据库你想显示/检索哪个列的数据

select t.name tells the database which column you want to show/retrieve data for

from users_chars uc 从 users_chars 表中获取数据,并给它一个别名uc"(如果 UC 中不存在该 ID,您将无法从table_two)

from users_chars uc get data from the users_chars table and give it an alias of "uc" (if the ID doesn't exist in UC, you won't be able to get the name from table_two)

inner join table_two t on uc.pos_zone = t.zone_id users_chars 表中的 pos_zone 列包含与 table_two 中的 zone_id 相同的数据,因此将这两个链接在一起(通常是外键关系,但它不一定是).还要给 table_two 一个别名t"

inner join table_two t on uc.pos_zone = t.zone_id pos_zone column from the users_chars table contains the same data as zone_id in table_two, so link those 2 together (typically a foreign key relationship, but it doesn't have to be). Also give table_two an alias of "t"

这篇关于需要与表格进行比较并显示一行数据而不是其他的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆