--- last_review: "2026-05-07" last_reviewer: "Nina Rosnerski" documented_code: [ ] --- ```{tags} user, tutorial, query ``` # Finding Data - How to find {term}`records ` stored in LinkAhead. - How to filter results by their {term}`properties ` - How to filter results by their by relations to other records. ::: This tutorial covers the basics of searching for data in LinkAhead. For more in-depth explanations, you may also look at the [query overview page](/explanation/general/linkahead_query_language.md), and if you want to get results in tabular form, refer to the tutorial [Get tabular data in LinkAhead](./query_select.md). :::{tip} In the past, "LQL" was called "CQL". There may still be instances where the old term is used. ::: ## Prerequisites - You need access to the web interface of a LinkAhead instance with the demo data. - For example the demo server at . - Alternatively you can use a LinkAhead instance which you installed locally or which was provided by your university or company. In this case, if your instance does not contain the data used in the LinkAhead demo, you will need to adjust the queries to match your own data. - As no data will be added or updated in this tutorial, read‑only access is sufficient. Make sure you can open the LinkAhead web interface and see the query field at the top of the page (before you start typing any query). ## First steps with LinkAhead Queries The semantic data model of LinkAhead allows efficient data access. We use the LinkAhead Query Language (LQL) to search the data. You can enter queries directly in the webinterface: :::{figure} /.assets/images/tutorials/webinterface/query/search_bar.png :align: center :alt: Search bar in the web interface :figclass: mwpx-800 Search bar in the web interface ::: ### Our first query Let's start with a simple one: ```lql FIND MusicalInstrument ``` You should now see the musical instrument Records which are stored in LinkAhead: :::{figure} /.assets/images/tutorials/webinterface/query/search_results_musicalinstrument.png :align: center :alt: Search results in the web interface: A few musical instruments Search results in the web interface: A few musical instruments ::: :::{admonition} Explanation :class: tip Most queries simply start with the `FIND` keyword and describe what we are looking for behind that. Then, we provided a {term}`RecordType` name: `MusicalInstrument`. This means that we will get all records that have this RecordType as {term}`parent `. ::: ### There are more Entities than Records Now try out the next query: ```lql FIND ENTITY Guitar ``` :::{admonition} Explanation :class: tip dropdown When we add the `ENTITY` keyword we will get every entity that is a Guitar -- also the RecordType, and even a Property with that name if there exists one. Using `FIND RECORDTYPE Guitar` would restrict the result to only that RecordType. And `FIND RECORD MusicalInstrument` is equivalent to `FIND MusicalInstrument`. ::: Note, that you can provide not only RecordType names after the `FIND`, but names in general: ```lql FIND "Nice Guitar" ``` This will give you a Record with the name "Nice Guitar" (this one exists in the demo instance). Quotes `"..."` are necessary if the name contains spaces. There are some features that make it easier to use names in queries: - The LinkAhead Query Language is generally case insensitive. - You can use `*` to match any string: `FIND Nice*` or `FIND RECORDTYPE Musical*`. - In the webinterface, after typing three letters, names that start with these letters will be suggested by the autocompletion. :::{admonition} Exercise :class: note Predict the result of the query before you run it. This helps you get a feeling for the filters. ::: ## Filter your search results with Properties Looking for entities with certain names or such that have certain parents is nice. However, the queries become really useful if we can impose further restrictions on the results. Let's start with an example again: ```lql FIND Guitar WITH price > 10000 ``` This will list expensive guitars that are in the demo instance. :::{admonition} Explanation :class: tip dropdown Here we are using a property (the price) of the `Guitar` records to restrict the result set. In general such a restriction or filter looks like: ```lql FIND WITH ``` ::: Typically, the filter has the form ` `, for example `length >= 0.7mm`. Instead of the `` you can also use one of the entity roles, namely `RECORD`, `RECORDTYPE`, `FILE`, `PROPERTY`, or `ENTITY`. :::{seealso} :class: dropdown There are many filters and operators available. You can check the [query language specification](/reference/general/lql_reference.md) for a comprehensive description of the available filters. In this tutorial, we will only look at the most common examples. ::: :::{tip} Note that in the above example the value of `length` has a unit `mm` while in the previous example the value `10000` did not have a unit. However, units are not covered by this tutorial. ::: If you want to find records which have a certain Property, but you are not interested in the Property's value, you can use: ```lql FIND MusicalInstrument WITH Manufacturer ``` This returns all MusicalInstrument records which have a Manufacturer as a property. Similarly to using incomplete names, you can use `LIKE` and `*` to match parts of text properties: ``` FIND RECORD WITH serialNumber LIKE KN* ``` There is large number of operators that can be used together with dates or times. One of the most useful is probably: ```lql FIND RECORD WITH date IN 2019 ``` Here the date must be in the year 2019, but the month and day are irrelevant. ## References between Records A lot of valuable information is often stored in the relations among data, i.e. in the references of entities. So how can we use those? Try it out: ```lql FIND RECORD WHICH REFERENCES A Guitar ``` This returns all records which reference a `Guitar` Record. And it is also possible to check for references in the other direction: ```lql FIND RECORD WHICH IS REFERENCED BY A Analysis ``` You can also provide the ID of an entity to find referencing records: ``` FIND RECORD WHICH IS REFERENCED BY 112 ``` ## Using multiple filters ### AND / OR Often, one filter is not sufficient. Thus multiple filters can be combined: ```lql FIND (AND|OR) ``` Try this out for yourself and enter this search query: ```lql FIND Guitar WITH price>48 AND electric=TRUE ``` This example returns all guitars that are electric AND have a price above 48. :::{tip} The query language also supports clustering filters with parentheses, but this is not covered by this tutorial. ::: ### Nested reference filters Furthermore, reference filters can be nested: ```lql FIND WHICH REFERENCES WHICH REFERENCES ``` An example with two hops, `Manufacturer` ← referenced by `Guitar` ← referenced by `MusicalAnalysis` records: ```lql FIND Manufacturer WHICH IS REFERENCED BY Guitar WHICH IS REFERENCED BY MusicalAnalysis ``` ## Just the numbers, please: Count results Using `COUNT` instead of `FIND` will only return the number of entities in the result set: ```lql COUNT Guitar WHICH IS REFERENCED BY MusicalAnalysis ``` :::{tip} This is often useful when experimenting with queries. Getting only the number of results can be faster than returning all the results. ::: ## Next steps Congratulations! You finished the tutorial Finding data in LinkAhead. Next, you may be interested in the tutorial [Get tabular data in LinkAhead](query_select.md), where you will assemble your own data tables and download the results, so you can analize the data with your day-to-day tools. There is also more in-depth information about LinkAhead queries in the [query overview page](/explanation/general/linkahead_query_language.md).