Reputation: 104
I have two tables:
images
imageid imageKeySTring
------- --------------
98 AAA
97 BBB
96 CCC
95 CCC
94 BBB
objects
imageKeyString id2
-------------- -----
AAA 2
BBB 3
AAA 4
CCC 5
CCC 6
BBB 7
All combinations of id2
with imageid
linked by matching imageKeyString
how would I get this in an Oracle SQL query?
Example, for CCC
I would get back:
5/95
5/96
6/95
6/96
returned (but I want all key returned values in the query)
Upvotes: 1
Views: 236
Reputation: 1269445
You need to join the tables together AND concatenate the results:
select i.imageKeyString,
cast(o.id2 as varchar(10)||'/'||cast(i.imageid as varchar(10)) as newkey
from images i join
objects o
on i.imageKeyString = o.ImageKeyString
If some objects are missing:
select i.imageKeyString,
coalesce(cast(o.id2 as varchar(10), '')||'/'||cast(i.imageid as varchar(10)) as newkey
from images i left outer join
objects o
on i.imageKeyString = o.ImageKeyString
Upvotes: 0
Reputation: 238048
Looks like a join
would do what you ask. It returns all matching rows from the joined table:
select i.imageid
, o.id2
from images i
join objects o
on o.imageKeyString = s.ImageKeyString
Upvotes: 3