gpt4 book ai didi

php - 在外键 id php 上插入 mysql

转载 作者:行者123 更新时间:2023-11-29 05:54:38 27 4
gpt4 key购买 nike

我有 2 张 table 、俱乐部和固定装置

俱乐部

id (int)
name (text)

装置

id (int)
hometeam (int, foreign key to clubs id)
awayteam (int, foreign key to clubs id)
datetime (datetime)

每个 fixtures 记录根据外键关系使用 hometeamawayteam 的 ID。

我需要插入到 fixtures 表中,但我只有 hometeam 名称,没有 hometeam id。有没有办法通过外键关系做到这一点,而不必单独查找相关的 ID 号?

最佳答案

通过单独的选择查询查找外键值没有错:

INSERT INTO `fixtures`
VALUES ( NULL,
(SELECT `id` FROM `clubs` WHERE `name` = 'NAME'),
AWAYTEAM_ID,
CURRENT_TIMESTAMP
);

关于php - 在外键 id php 上插入 mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50795607/

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