i have to join 2 views view_a and view_b.
view_a has columns id,address1,address2,city,state,cntry
view_b id,frst_name,last_name,type,date,job_title
desired result
id,Name,address1,address2,city,state,cntry,job_title
Conditions for my query are:
1. join both views on id column.
2. order by date desc
3. concatenate first_name and last_name
4. type equals to "officer"
5. If there are more than one officer then yield only one officer i.e., one top row based on the date.
6. If there is no officer then have null value for the name and job_title column in the result.
Query I have used:
select
*
from
view_a A
join
(
select
(first_name || ' ' || last_name) as name,
job_title,
id
from
view_b
where
type = 'officer'
and
id is not null
order by date desc fetch first 1 row only
) B
on A.id=B.id
But this query is yielding only one result. I'm using Oracle 12c. there are about 800K records in these views.
You can do this: