I have run into a problem where some IDs have multiple names associated with them. That is, if I have a location ID from one table and need to pull the location's name from another table based on the location ID, the query is returning multiple names. I want to choose the newest name based on a timestamp, if that one is not blank (that is, it's not null, but many of the entries are just a blank space).
TABLE LOCATIONS:
LOCATION_ID LOCATION_NAME LOCATION_TS
12345 'BEST AUTO' 4
12345 'BESTAUTO' 3
12345 ' ' 5
12347 'FETTS' 3
12347 'FESTS' 2
TABLE LOCATION_DETAIL:
LOCATION_ID LOCATION_TYPE
12345 'AA'
12347 'ZQ'
I am trying to get a result that looks like this:
LOCATION_ID LOCATION_NAME LOCATION_TYPE
12345 'BEST AUTO' 'AA'
12347 'FETTS' 'ZQ'
Here is an SQLfiddle. I am using Oracle 11g. I have been spinning my wheels on this for a while and I feel like I'm missing something obvious. I should mention that the way my permissions are set up, pretty much the only thing I can do is query the database, not create views or tables, update data, etc.