Reputation: 59
1:Table COUNTRY
ID NAME
1 USA
2 BRITAIN
2:Table PEOPLE
P_ID P_NAME
4 JOHN
5 MONTY
Resultant table should have
ID NAME P_ID P_NAME
1 USA 4 JOHN
2 BRITAIN 5 MONTY
Just side by side merge. Is it possible? LIKE TABLE1 | TABLE2
Upvotes: 3
Views: 3168
Reputation: 1453
If I well understood your question this could work:
SELECT *
FROM (SELECT T1.*,ROWNUM AS R FROM COUNTRY T1) V1,
(SELECT T2.*,ROWNUM AS R FROM PEOPLE T2) V2
WHERE V1.R = V2.R(+)
But you need to know wich table is bigger and I fear you aren't going to to get reliable results
Upvotes: 3
Reputation: 3473
Try this:
SELECT * FROM COUNTRY C
INNER JOIN PEOPLE P ON C.ID = P.P_ID;
Updated answer :
Select * from #country as c , #people as p where p_id =4 and id=1 OR id = 2 and p_id=5
Upvotes: 0
Reputation: 485
Example
with x as (
select id, name, rownum rn from country
order by id),
y as(
select p_id, p_name, rownum rn from people
order by p_id)
select id,name,p_id,p_name from x
left join y on y.rn = x.rn
union
select id,name,p_id,p_name from y
left join x on y.rn = x.rn
Upvotes: 5
Reputation: 879
This should work..
select c.id,c.name, p.p_id, p.p_name from country c inner join people p on c.id = p.p_id;
Upvotes: 0