gpt4 book ai didi

mysql - Codeigniter 模型,根据 table1 从 2 个表中获取值。如果在 table2 上找不到值,则值返回 null

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

我先说明一下我的情况所以我有两张表,一张是表 tb_form,第二张是 tb_pendaftaran

tb_form         tb_pendaftaranid_form         id_pendaftaranjudul           id_formvalue           value

然后我想显示tb_form中的所有judul,并从tb_pendaftaran中获取值。

情况 1:tb_form 有 5 个 id_form,所有 id_form 也在 tb_pendaftaran 中。一切正常,所有记录都显示了

在情况 2 中:但现在的问题是,当 tb_form 有 5 个 id_form,而 tb_pendaftaran 只有 3 个 id 时,结果只显示 3 条记录而不是 5 条。我想显示基于表一的所有五个 judul,如果它没有 tb_pendaftaran 的值,那么该值应该不显示任何内容

*抱歉我的英语不好

谢谢,感谢您的帮助

最佳答案

There是一个很好的 sql 连接图。只需查看页面底部即可。

在您的情况下,您应该使用以下 sql 短语:

select f.*, p.id_pendaftaran, p.value from tb_form f 
left join tb_pendaftaran p on f.id_form = p.id_form

因此,您将列出第一个表中的所有行,如果表 tb_pendaftaran 上有任何匹配项,则相关列将被填充。

enter image description here

关于mysql - Codeigniter 模型,根据 table1 从 2 个表中获取值。如果在 table2 上找不到值,则值返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49622232/

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