prasant Jinaga Ответов: 1

Объедините два запроса в oracle и получите комбинированный запрос


I have two queries which results below data from each table

Query 1

Address_ID	Display Value	     Account_ID
1000	        10001 - Test 1	     100
1000	        10002 - Test 2	     200
1000	        10003 - Test 3	     300


Query 2

Address_ID	Display Value	   Account_ID
2000	        10001 - Test 1	   100
3000	        10004 - Test 4	   400


I need to combine these Queries and get the data as below as we see Account ID (100) do exist the same from both queries take row for that Account ID from first Query.

Address_ID	Display Value	 Account_ID
1000	      10001 - Test 1	100
1000	      10002 - Test 2	200
1000	      10003 - Test 3	300
3000	      10004 - Test 4	400


Any help is much appriciated.


Что я уже пробовал:

Я пробовал и с Союзом и с минусом и с присоединениями тоже

1 Ответов

Рейтинг:
11

Member 14886390

For both SQL Server and Oracle you can use this sort of construction....
Select Address_ID, Display_Value, Account_ID
from FirstTable
union
Select Address_ID, Display_Value, Account_ID
from SecondTable
Where SecondTable.Account_ID not in (select FirstTable.Account_ID from FirstTable);