[英]how to compare values from different tables with same name mysql
i have 2 tables 我有2张桌子
table A 表A
Question|Answer
-------------------
a | y
table B 表B
Type | Question
------------------
3 | a
---------------
1 | b
how do i check what type question A is from Table A by looking at it from table B? 我如何通过查看表B来检查表A的问题类型A? i want to check if question a from table A is type 3 (do this) if it is type 1 (do this) cant find the right query
我想检查表A的问题a是否为类型3(执行此操作)是否为类型1(执行此操作)找不到正确的查询
maybe Select type from table B where tableA.question = tableB.question
SELECT b.Type FROM TableA a, TableB b WHERE a.Question=b.Question
Effectively what you need to do here is perform a join in your query, so that you return the type along with the question and answer in your result set. 实际上,您需要在查询中执行联接,以便在结果集中返回类型以及问题和答案。
You can use the following SQL; 您可以使用以下SQL;
SELECT a.question, a.answer, b.type FROM TableA a INNER JOIN TableB b ON a.question=b.question
Hope this helps. 希望这可以帮助。
You can JOIN both tables and then perform the logic in PHP. 您可以联接两个表,然后在PHP中执行逻辑。
SELECT
a.question as question,
a.answer as answer,
b.type as type
FROM
table_a a, table_b b
WHERE
a.question = b.question;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.