gpt4 book ai didi

php - 如何使用ID从关联表中获取值?

转载 作者:行者123 更新时间:2023-11-29 06:06:36 25 4
gpt4 key购买 nike

首先我不知道标题是否相关(如果不相关请原谅)。

我有 2 个表userprofilecountry

userprofile table:-
-----------------------------------------
userid | email |............|**countryid**
-----------------------------------------

country table:-
-----------------------------------------
**countryid** | countryname
-----------------------------------------

我想从userpfofile表中选择数据,即 $query="select * from userprofile ...但问题是该数据返回countryid,但我实际上想返回countryname。

我是 MySQL 新手,所以请建议实现此目的的最佳方法。

最佳答案

您需要join将这两个表放在一起即可获取您想要的数据,如下所示:

SELECT * FROM userprofile u
LEFT JOIN country c
ON c.countryid = u.countryid

这将产生类似于以下内容的结果集:

---------------------------------------------------------
| userid | email | .......... | countryid | countryname |
---------------------------------------------------------

关于php - 如何使用ID从关联表中获取值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11264421/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com