-1

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

pos_zone
255

在表二

zone_id | name
 255    | This_Area

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

4

2 回答 2

1
select t.name
from users_chars c
inner join table_two t on c.pos_zone = t.zone_id
where c.pos_zone = 255
于 2013-08-01T15:57:27.413 回答
1
select t.name
from users_chars uc
inner join table_two t on uc.pos_zone = t.zone_id

这意味着什么:

select t.name告诉数据库您要显示/检索数据的列

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

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

于 2013-08-01T16:09:07.843 回答