...
It is possible that a given record will not have any LC subject headings. In the screenshot below we see a typical example of subject headings in a record. The first 2 lines in the screenshot show two parts of a single subject heading: 650 0 $a Cultural property $x Protection (International law). The number 1 in the ord column tells us that these two subfields are the elements that make up the first subject heading in the record. The second subject heading has 3 separate elements, divided into three subfields: 650 0 ‡a Cultural property ‡x Protection ‡z Europe .
And and so on. There are 4 LC subject headings in this record, and numerous other subject terms as well. To find the first subject term in a record, I recommend using that number 1 in the ord field.
...
For example, to pull the first LOC subject heading from a bibliographic record using its instance hrid, you would use:
SELECT DISTINCT
SM.instance_hrid,
SM.field,
SM.ind2,
SM.ord,
SM.sf,
SM."content"
FROM
public.srs_marctab SM
WHERE SM.instance_hrid = '15309598'
AND SM.field LIKE '6%%'
AND SM.ord='1'
AND SM.ind2='0'
;
Which results in:
Further, if you want to display the subject heading as it appears in the bibliographic record, you may use a STRING_AGG FUNCTION to format the content rows as a subject heading string. Here is an example using instance HRIDs between 6403921 and 6404000:
WITH lc as
(select distinct SELECT DISTINCT
sm.instance_hrid,
sm.field,
sm.content
FROM from srs_marctab sm sm
where
WHERE sm.instance_hrid = between '6403921' and '153095986404000'
and AND sm.field like '6%%'
andAND sm.sf in ('a','x','y','z')
andAND sm.ind2 = '0'
andAND sm.ord = '1'
)
SELECT
) select lc.instance_hrid,
lc.field,
string_agg (distinct lc.content, ' -- ') as lc_subject from
FROM lc
GROUP groupBY
by lc.instance_hrid,
lc.field ;
;
And the results would be:

