Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
153 views
in Technique[技术] by (71.8m points)

php - Need to compare to tables and show one rows data in place of other

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

pos_zone
255

in table two

zone_id | name
 255    | This_Area

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
select t.name
from users_chars uc
inner join table_two t on uc.pos_zone = t.zone_id

What this means:

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

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 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"


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...