Queries are the meat of a TriNetX study. A study can have one query or many. They can be almost identical but run on different networks, age groups or time periods, or they can be completely different from one another.
Once a query is built, the TNX analytics features help you gain insights. Those insights might encourage you to go ahead with a research project, edit your query, or take your research in a new direction.
What is a query in TNX?
A query asks for the details of the patient population you specify. You define that population with Must Have and Cannot Have criteria, just like the inclusion and exclusion criteria in a written study protocol. The patients who fit your criteria are your cohort.

Build a basic query
Click New Query
in the upper right of the Query Builder to add a brand-new query to the study.
Choose a network
At the top of your query in the Query Builder, you select a data network. Click the network name to see your other choices.

All networks let you run analyses on your query's cohort, but not all of them allow dataset downloads. Each query in a study can use a different network, and you can easily switch a query to another network if you change your mind. See Networks in TriNetX.

Choose filters
Query results can be filtered by medical center type, data types, and age and sex.
- Medical center type: HCOs sharing data can be Academic, Non-Academic or Unknown.
- Data types: HCOs sharing data must have the types you select: Demographics, Diagnoses, Genomics, Labs, Meds or Procedures.
- Age and sex: select for patients' sex or current age. The age reflects each patient's current age on the day you count the patients in your query.

Find and add terms
Use the search boxes to find your criteria. You can enter known codes, or text if you don't know the code. General text lets you narrow things down from the results. For example, here is a text search for "Liver".

The results include diagnoses, labs, procedures, medications and genomics. Tip: to see only diagnoses, click the highlighted Diagnoses filter button.
Drill down to a more specific liver disease diagnosis by hovering over the term, then clicking the blue tree for that code.

Once a tree is open, you may also see codes with blue sideways arrows
. Click those to expand them and show subcodes.
Tick the terms you want, then click Add to Query. New terms appear on the Must Have or Cannot Have side, wherever you searched. Lab terms let you enter values, and choose whether the most recent lab result must meet them or any value in the patient's history. You can drag terms from one side to the other as needed.

Count patients and name your query
Click Count Patients, the rounded arrows
, to see how many patients in your chosen network fit your criteria.
Name each query so you can find it again among your other queries. Click the pencil to edit the name at any time.

Timesaver tip: don't rebuild your query!
You can import a query from any study you created, that was shared with you, or that is a template in the system, even the study you are in now. In a new blank query, select Import Query. Pick the study with the query you want, then choose the query to import it as your new query. This saves effort when you just want to edit the original.

Build a complex query
Real study questions are rarely simple. Here are some more advanced tricks for fine-tuning your queries.
Filter a single term
The funnel on a term lets you add filters to it, such as Age at Event, or details about cancer, medications or labs. For example, you can require patients in your cohort to have been a certain age when something happened in their health history.


The power of the group
Groups help you organize and fine-tune your query. Use them to set time constraints, require a number of instances or unique instances of terms, and create time relationships between two related groups.
Click Create a New Group at the bottom of the Query Builder page. Terms must first be searched and added to your main query from the main search box. Then use the Add Terms button to pick from a checklist of your query's ungrouped terms.

Group Rules
Click Group Rules in your group box to set any of these: number of instances, number of unique instances, a related group, or a time constraint.

Add a time constraint
You can filter for when terms happened. Click Time Constraint and set a Relative Time (say, within the last 3 months) or Specific Dates (maybe March 1, 2020 to March 1, 2021). You can have several groups, each with its own constraint.

The constraint applies to every term in that group. Terms not moved into the group are not affected.

Create a related group
You may want patients who had your terms in a time relationship to other terms. Create a group for your first terms, then click Add Related Group in Group Rules. Now you have groups A and B. Add the terms you want to relate to group A into group B, then click to set the relationship.

Imagine group A stays firmly in place. Group B can move ahead of or behind group A by the time period you set.
You can also set the instance type for each group. For example, if your term were a myocardial infarction, you might choose the Most Recent Instance, or the First Instance.

