Bhushan Gadekar
Bhushan Gadekar

Reputation: 91

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.

I want to retrieve the records having Call_Status="Open" from both tables. i.e. I want a query that can retrieve all the records of table1 having call_Status="Open" & then from table2 having call_Status="Open"

I have no idea how to do this and would appreciate some guidance

Upvotes: 2

Views: 7443

Answers (3)

khelwood
khelwood

Reputation: 59112

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.

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.

Upvotes: 5

MeshBoy
MeshBoy

Reputation: 692

You can join the two tables by the attribute call_status like below.

SELECT (Your column names) FROM table1 INNER JOIN table2 ON Table1.call_status='open' and Table2.call_status='open';

Upvotes: 0

praveen_programmer
praveen_programmer

Reputation: 1062

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' ;

Upvotes: 0

Related Questions