I am trying to duplicate a query from sqlserver which returns a single row from a one to many join.
E.g. (rough example) you have a table of people, this is linked to a table with their phone numbers (of which they may have many). The query needs to return all the people, and just one (doesnt matter which really for now) of their number (the list is intended to be expanded later - which is why we only want one row).
So people table :-
ID, NAME
1,tom
2,dick
3,harry
...
And the numbers :-
UID, OWNER, NUMBER
1, 1, 1234567
2, 1, 1231231
3, 2, 11223344
...
What I want is a query that gets
tom, 1234567
dick, 11223344
harry,
...
In SQLServer this has been done kinda like :-
SELECT People.Name, Phone.Number
FROM People
LEFT OUTER JOIN Phone on People.id=Phone.owner
and (Phone.UID=(select top 1 UID from Phone WHERE Owner=People.ID))
But I seem to be unable to do something similar in Oracle.
Suggestions welcome
Thanks,
<< JOC >>
E.g. (rough example) you have a table of people, this is linked to a table with their phone numbers (of which they may have many). The query needs to return all the people, and just one (doesnt matter which really for now) of their number (the list is intended to be expanded later - which is why we only want one row).
So people table :-
ID, NAME
1,tom
2,dick
3,harry
...
And the numbers :-
UID, OWNER, NUMBER
1, 1, 1234567
2, 1, 1231231
3, 2, 11223344
...
What I want is a query that gets
tom, 1234567
dick, 11223344
harry,
...
In SQLServer this has been done kinda like :-
SELECT People.Name, Phone.Number
FROM People
LEFT OUTER JOIN Phone on People.id=Phone.owner
and (Phone.UID=(select top 1 UID from Phone WHERE Owner=People.ID))
But I seem to be unable to do something similar in Oracle.
Suggestions welcome
Thanks,
<< JOC >>