简体   繁体   English

如何从两个表中选择两个在同一个字段中具有相同值的行?

[英]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.

相关问题 如何从两个具有相同类值的表中选择一个表? - How to select one of the tables from two tables with the same class value? 选择0/1背包中的物品,其中两个物品具有相同的好处|最大化价值并最小化重量 - Select items in 0/1 knapsack ,where two items have same benefits |maximize value and minimize weight 从具有相同主键的两个表中删除行 - Delete rows from two tables with same primary key 如果所有子记录中的字段都相同,如何选择字段值 - How to select the field value if field in all child records are the same 我有两个 hashmap HashMap <string,list<string> &gt; 在这种格式下,如何比较两个值是否相同或不同的键</string,list<string> - I have two hashmap HashMap<String,List<String>> in this format how to compare both the values are same or not with same keys 如何显示这两个数组在两个数组中的同一位置具有相同的数字? - How to display if those two arrays have the same number on the same place in both arrays? Hibernate sql 查询有两个相同的表,预计返回具有相同名称但不同值的列,但它返回相同的值 - Hibernate sql query has two same tables and is expected to return colums that have same name but different values , but it returns same value 如果我从第一个ArrayList中删除了一个值,如何在两个ArrayList上获得相同的位置 - How to get the same position on two ArrayListif I have removed a value from the first ArrayList 检索列具有相同值的不同行并通过没有游标超时来进行迭代? - Retrieving distinct rows where columns have the same value and iterating by not having a cursor timeout? 如何在Appium中验证两个元素的值相同? - How to verify two elements have the same value in Appium?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM