gpt4 book ai didi

mysql - 连接 3 个表,其中 2 个被 SELECT *

转载 作者:行者123 更新时间:2023-11-29 03:09:19 27 4
gpt4 key购买 nike

我正在通过重测进行研究。我有三张 table 。一张表用于人口统计,我只需要其中的有限数据。另外两个表各有 235 个字段,唯一的区别是表名。我试过这样的陈述:

SELECT * FROM research_statement_answers, statement_answers, demographic_answers
WHERE (( research_statement_answers.id_Questions = demographic_answers.id_Demographic)
and (statement_answers.id_Questions = demographic_answers.id_Demographic)
and (demographic_answers.Research_Completed = 1))

但这行不通。我见过的所有示例都要求我命名两个表中的所有 235 个字段。我能做到,但我不相信这是最好的方法。因此,我们非常欢迎提出建议。谢谢。瑞克

最佳答案

SELECT
research_statement_answers.*,
statement_answers.*,
demographic_answers.*
FROM ...

既然这些表只是名称不同,那么对它们使用 UNION JOIN 不是更好吗?

结果将是所有表记录的重聚。

使用普通连接,结果是每条记录 235*3 列,记录的子集表示三个表之间的交集。

关于mysql - 连接 3 个表,其中 2 个被 SELECT *,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10771341/

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