I'm trying to look up two pieces of metadata (volume and issue) on items which may have either a volume, issue, or both. The metadata is stored in a table with item ID, key (metadata field ID) and value.
This does work, but it seems overly complex and repetitive:
select volume.text_value as volume_value, issue.text_value as issue_value
from metadatavalue item
left outer join (select item_id, text_value from metadatavalue
where metadata_field_id = 90) volume
on item.item_id = volume.item_id
left outer join (select item_id, text_value from metadatavalue
where metadata_field_id = 91) issue
on item.item_id = issue.item_id
where item.metadata_field_id in (90, 91)
Is there a simpler way to write this query?
Thanks.