> For the complete documentation index, see [llms.txt](https://docs.snomed.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.snomed.org/implementation-guides/loinc-implementation-guide/technical-application/6.4-using-the-loinc-ontology/6.4.3-accessing-the-reference-set-in-a-relational-database.md).

# Accessing the Reference Set in a Relational Database

If the LOINC Ontology has been loaded in a relational database using a model that complies with the RF2 specification for tables and column names, the content can be accessed using SQL queries in line with the examples below. To Set up SNOMED CT in a relational database, please follow the guidance and instructions provided in the [SQL Practical Guide](https://docs.snomed.org/snomed-ct-practical-guides/snomed-ct-sql-practical-guide/).

## SQL Examples <a href="#id-6.4.3accessingthereferencesetinarelationaldatabase-sqlexamples" id="id-6.4.3accessingthereferencesetinarelationaldatabase-sqlexamples"></a>

<table data-full-width="true"><thead><tr><th>Service Name</th><th>SQL Query</th><th>Result</th></tr></thead><tbody><tr><td><p><strong>Get all members of the reference set</strong><br></p><p><strong>The reference set used in this example is:</strong></p><p>635111010000100 |Logical Observation Identifiers Names and Codes Orderable Reference Set (foundation metadata concept)|</p></td><td><pre class="language-sql" data-overflow="wrap"><code class="lang-sql">SELECT referencedComponentId FROM snap_refset_simple WHERE active=1 AND refsetId=[refsetId];
</code></pre><p>for example</p><pre class="language-sql" data-overflow="wrap"><code class="lang-sql">SELECT referencedComponentId FROM snap_refset_simple WHERE active=1 AND refsetId=635111010000100;
</code></pre></td><td>Returns the ids of all the concepts or descriptions that are the members of the reference set.</td></tr><tr><td><p><strong>Test if a concept is a member of the reference set</strong></p><p><strong>The concept used in this example is:</strong><br>141951010000102 |Mass concentration of neopterin in urine at point in time (observable entity)|<br></p></td><td><pre class="language-sql" data-overflow="wrap"><code class="lang-sql">SELECT count(referencedComponentId) FROM snap_refset_simple WHERE active=1 AND refsetId=[refsetId] AND referencedComponentId=[candidateComponentId];
</code></pre><p>for example</p><pre class="language-sql" data-overflow="wrap"><code class="lang-sql">SELECT count(referencedComponentId) FROM snap_refset_simple WHERE active=1 AND refsetId=635111010000100 AND referencedComponentId=141951010000102;
</code></pre></td><td><p><br></p><p>Returns:</p><ul><li>0 : if the candidate component is not in the reference set.</li><li><p>1 : If the candidate component is a member of the reference set</p><ul><li>Some types or reference set can include the same component more than once, so any value greater than zero indicate the component is a member of the references set.</li></ul></li></ul></td></tr></tbody></table>

<a href="https://docs.google.com/forms/d/e/1FAIpQLScTmbZIf0UEQwYDkY27EEWBkaiYkHSbR0_9DmFrMLXoQLyL7Q/viewform?usp=pp_url&#x26;entry.1767247133=LOINC+Implementation+Guide&#x26;entry.670899847=Accessing%20the%20Reference%20Set%20in%20a%20Relational%20Database" class="button primary">Provide Feedback</a>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.snomed.org/implementation-guides/loinc-implementation-guide/technical-application/6.4-using-the-loinc-ontology/6.4.3-accessing-the-reference-set-in-a-relational-database.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
