[英]How to select rows from two tables where both have the same value in the same field?
I have two tables that have the same column names. 我有两个具有相同列名的表。
There is a field called Call_Status
in both tables. 两个表中都有一个名为Call_Status
的字段。
I want to retrieve the records having Call_Status="Open"
from both tables. 我想从两个表中检索具有Call_Status="Open"
的记录。 ie I want a query that can retrieve all the records of table1
having call_Status="Open"
& then from table2
having call_Status="Open"
即我想要一个查询,可以检索具有call_Status="Open"
的table1
所有记录,然后从table2
call_Status="Open"
I have no idea how to do this and would appreciate some guidance 我不知道如何做到这一点,并希望得到一些指导
If you want to get all the matching rows from the first table and all the matching rows from the second table (as opposed to joining rows together), then you could use a union. 如果要从第一个表中获取所有匹配的行以及从第二个表中获取所有匹配的行(而不是将行连接在一起),则可以使用union。
SELECT column names FROM table1 WHERE call_status='Open'
UNION ALL
SELECT column names FROM table2 WHERE call_status='Open'
You can use UNION
instead of UNION ALL
to get unique rows, as pointed out by Fionnuala. 您可以使用UNION
而不是UNION ALL
来获取唯一的行,如Fionnuala所指出的那样。
you can use join query. 你可以使用连接查询。
SELECT column_name(s)
FROM table1
INNER JOIN table2
ON table1.Call_Status=table2.Call_Status and table1.Call_Status='Open' ;
You can join the two tables by the attribute call_status like below. 您可以通过属性call_status加入这两个表,如下所示。
SELECT (Your column names)
FROM table1 INNER JOIN table2
ON Table1.call_status='open' and Table2.call_status='open';
SELECT (Your column names)
FROM table1 INNER JOIN table2
ON Table1.call_status='open' and Table2.call_status='open';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.