比较两个不同表中的两列? [英] Comparing two columns in two different tables?

查看:65
本文介绍了比较两个不同表中的两列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,如果问题的语法和框架不符合标准,我们深表歉意.

First of all apologies for if the syntax and framing of question isn't up to the standards.

我有一个 MySql 数据库.我有一个表答案,其中包含 idquestion、userAnswer、userEmailAddress 作为列.

I have a MySql database .I have a table answer which contains idquestion, userAnswer, userEmailAddress as columns.

另一个表 multi_choice_pool,其中包含 idQuestion、answer_all.

Another table multi_choice_pool, which contains idQuestion, answer_all.

每个 answer.userEmailAddress 都有多个 idQuestion 和 userAnswer 条目.

Every answer.userEmailAddress has multiple entries of idQuestion and userAnswer.

我想在 answer 表中获取 userEmailAddress ,其中 userEmailAddress 的 id 和 answer 等于 multi_choice_pool 的 iq 和 answer.

I want to obtain userEmailAddress in answer table where id and answer of that userEmailAddress equals the iq and answer of multi_choice_pool.

我是这样写的:

Select answer.userEmailAddress from answer 
where (answer.idQuestion=multi_choice_pool.idQuestion) AND  
(answer.userAnswer=multi_choice_pool.answer_all);

这给了我一个错误:where 子句中的未知列 'multi_choice_pool'.

Which is giving me an error: "Unknown column 'multi_choice_pool' in where clause.

语法错误吗?或者查询本身是错误的?还是我的方法不对?你能改正并提供建议吗?

Is the syntax wrong? Or the query is wrong itself? Or my approach isn't right? Can you rectify and provide suggestion?

推荐答案

Select answer.userEmailAddress 
from answer left join multi_choice_pool
on answer.idQuestion = multi_choice_pool.idQuestion 
and answer.userAnswer = multi_choice_pool.answer_all;

这篇关于比较两个不同表中的两列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆