2

我正在通过重新测试进行研究。我有三张桌子。一张表用于 Demographics,我只需要从中获取有限数量的数据。其他两个表各有 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 个字段。我可以做到,但我不敢相信这是最好的方法。因此,建议最受欢迎。谢谢你。瑞克

4

3 回答 3

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

由于这些表仅在名称上有所不同,在它们上使用 UNION JOIN 不是更好吗?

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

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

于 2012-05-27T03:05:05.863 回答
0

您可以通过执行以下操作从多个表中选择 * 并仅包含第三个表的特定列:

SELECT
    research_statement_answers.*,
    statement_answers.*,
    demographic_answers.id,
    demographic_answers.title,
    demographic_answers.etc
FROM ...
于 2012-05-27T03:12:44.927 回答
0
    SELECT 
    research_statement_answers.*, 
    statement_answers.*,
    demographic_answers.*
 FROM research_statement_answers
    JOIN demographic_answers ON demographic_answers.id_Demographic = research_statement_answers.id_Questions
    JOIN statement_answers ON demographic_answers.id_Demographic = statement_answers.id_Questions
    WHERE demographic_answers.Research_Completed = 1
于 2012-05-27T04:02:17.297 回答