You can use queries in NVivo to search your project materials in a range of different ways and for different purposes. For example, you can search for specific words or phrases, or find frequently occurring words, to help inform your coding. You can also search for material that has been coded to combinations of codes or to codes for particular classification attributes, which can help you identify patterns in your data. This page looks at some examples of different queries.

In brief, it covers the following:

  • How to conduct a text search query to search for specific words and phrases in selected materials
  • How to conduct a word frequency query to find the most frequently occurring words in selected materials
  • How to use coding queries to find content that has been coded to combinations of codes, cases or attribute values
  • How to use matrix coding queries to make comparisons and look for patterns in your data
  • How to use crosstab queries to compare codes between different values of a classification attribute

To follow the examples on this page, use the Environmental Change Down East sample project (as detailed in the Sample projects page).

Text search queries

A text search query allows you to search project items and folders for specific words and phrases. For example, you can search all files, files in a particular folder, or material that has been coded to particular codes.

To run a simple text search query, for example to search for the word ‘erosion’, follow these steps:

  1. Select Query Criteria in the Navigation View (in the ‘Queries’ group), then right click in the white space in the List View and select ‘New Query’ and ‘Text Search’. Alternatively, select the ‘Explore’ tab on the ribbon at the top of the screen, then select ‘Text Search’
  2. Choose where you would like to search. The default is ‘Files & Externals’, but if you would like to search specific items or folders, click on the appropriate button and make your selections in the dialog box that appears
  3. Enter the text you wish to search for in the ‘Search for’ box (for example, ‘erosion’). You can enter multiple words and/or use special characters and operators to assist with your search using the ‘Special’ button if required
  4. You can change ‘Spread to’ from the default ‘None’ if you would prefer to see more or less of the context around the word(s) in the query results
  5. Choose how precise you would like the search to be using the ‘Find’ slider on the right (for example, you can search for Exact matches, With stemmed words, With synonyms, etc.)
  6. Select ‘Run Query’

The Text Search query page that appears in the Details View.

The results of the text search query will then be displayed underneath in a series of tabs:

  • The Summary tab is the default display tab. It shows all files that contain the search word(s) and the number of occurrences.
  • The Reference tab displays a snippet showing the context of each instance of the search word, sorted by file. To see more or less context, you can highlight and then right click on the selected instance(s), select ‘Coding Context’ and change it. Alternatively, you can run the query again with a different ‘Spread to’ option, or click on the file location link to see the results highlighted in the original document.
  • File-specific tabs (for example PDF and Dataset) display the results for each file on a separate page.
  • The Word Tree tab displays the search results as a word tree, with the search term in the middle and the preceding and following text on either side (listed alphabetically). Double clicking on any part of a sentence will open it in the file where it appears. You can also export, print or copy the word tree by right clicking on it and selecting the required option from the menu.

If you want to keep a copy of your text search query, you can save the results as a new code (or merge them with an existing code), or you can save the query criteria for future use. Select the ‘Save Results…’ or ‘Save Criteria…’ button respectively.

For example, to save the query criteria from your most recent search, follow these steps:

  1. Select ‘Save Criteria…’
  2. Enter a name for the new query criteria (for example, Erosion) and a description if required
  3. Click ‘OK’

You can also filter a text search query according to a particular file classification type or types, or according to a particular attribute of a file classification. For example, you can run the previous query again but limit the search to items classified as a ‘Reference’ with the Year attribute set to 2010. To do this, open the saved Erosion query criteria (located in the List View of Query Criteria) and follow these steps:

  1. For the ‘Search in’ option, choose ‘Selected Items…’
  2. Select the ‘Filter’ button in the bottom left-hand corner
  3. Tick ‘Classified items where’ (the bottom option)
  4. Click ‘Select…’, choose the file classification and then the attribute that you want to filter your search by (in this case, ‘Reference’ and Year), then select ‘OK’
  5. Choose the filter criteria (in this case, ‘equals value’)
  6. Choose the value of the attribute you want to filter your search by (‘2010’)
  7. Select ‘Find Now’
  8. Look through the project items in the ‘Select Project Items’ dialog box by clicking on the folder names in the list on the left-hand side and using the ‘+’ signs to open sub-folders as required. Everything except the items that match the filter will be greyed out. You can select the applicable non-greyed out item(s), or, more simply, tick the ‘Files’ box to automatically select all non-greyed out files (do this now)
  9. Select ‘OK’
  10. Adjust the other search options as required (as described previously)
  11. Select ‘Run Query’

The search results will only include occurrences of the word ‘erosion’ in files classified as ‘Reference’ with the Year attribute set to ‘2010’. You can then save these results as a code, if you wish, as follows:

  1. Select ‘Save Results…’
  2. Choose whether to ‘Create Results as New Code or Case’ or ‘Merge Results into Existing Code or Case’
  3. Choose a Location. The default is to store the results code in the Query Results folder, but you can choose to store it in the Codes or Cases folder, or a sub-folder of these, instead. Keep Query Results as the location for this example
  4. Enter a name for the new code (for example, Erosion 2010) and a description if required
  5. Click ‘OK’

Word frequency queries

A word frequency query allows you to find the most frequently occurring words in different project items and folders, and display the results in different ways.

To run a word frequency query for project materials in the Interviews folder, for example, follow these steps:

  1. Select Query Criteria in the Navigation View (in the ‘Queries’ group), then right click in the white space in the List View and select ‘New Query’ and ‘Word Frequency’. Alternatively, select the ‘Explore’ tab on the ribbon at the top of the screen, then select the ‘Word Frequency’ option
  2. Choose where you would like to search. The default is ‘Files & Externals’, but if you would like to search specific items or folders, click on the appropriate button and make your selections in the dialog box that appears. For example, to run the query for the Interviews files only, click on the ‘Selected Folders…’ button, tick the Interviews sub-folder in the Files folder, then click ‘OK’. You can also filter the query as described for text search queries
  3. Enter the number of words you would like displayed (for example, 20) and the minimum word length (keep this as 3)
  4. Choose how precise you would like the search to be using the ‘Grouping’ slider on the right (for example, you can search for Exact matches, With stemmed words, With synonyms, etc.)
  5. Select ‘Run Query’

The Word Frequency criteria page that appears in the Details View.

The results of the word frequency query will then be displayed underneath in a series of tabs, including the following:

  • The Summary tab is the default display tab. It shows the most frequently occurring words and the number of occurrences.
  • The Word Cloud tab displays the most frequently occurring words in a word cloud. You can change the appearance of the word cloud using the menu at the top of the screen, and can export, print or copy it by right clicking on it and selecting the required option from the menu.

You can remove a particular word from the search results, and therefore also from the word cloud, by selecting it in the Summary tab. Then either right click and select ‘Add to Stop Words List’, or choose this option from the menu at the top of the screen. Select ‘OK’, then run the query again to view the updated results.

If you want to keep a copy of your word frequency query, you can save the query criteria in the Query Results folder (in the ‘Queries’ group) by selecting the ‘Save Criteria…’ button and giving the query an appropriate name.

Coding queries

Coding queries allow you to search content that has been coded to code(s) or case(s), using specific combinations of codes, cases or attribute values. For example, if you want to find out what males think about infrastructure in the sample project, follow these steps:

  1. Select Query Criteria in the Navigation View (in the ‘Queries’ group), then right click in the white space in the List View and select ‘New Query’ and ‘Coding’. Alternatively, select the ‘Explore’ tab on the ribbon at the top of the screen, then select the ‘Queries’ drop-down menu and choose ‘Coding’
  2. Choose where you would like to search. The default is ‘Files & Externals’, but if you would like to search specific items or folders, click on the appropriate button and make your selections in the dialog box that appears. You can also filter the query as described for text search queries
  3. For ‘of the following are true’, choose either ‘All’ or ‘Any’, depending on whether you want to find material that meets ALL the conditions you specify or just ANY of them. For example, to find material that has been coded to the Infrastructure code and has ‘Male’ as the value for the Gender attribute, choose ‘All’
  4. Next to ‘Coded to’ and ‘All Selected Codes or Cases’, click on the button with the ellipsis. Tick the applicable code(s) (for example, Infrastructure), then click ‘OK’
  5. Click on the ‘+’ sign at the end of the row to add a new condition
  6. In this new condition, change the value in the second box to ‘Any Case Where’. Click on the button with the ellipsis, then click on the ‘+’ sign next to the case classification you are interested in (for example, ‘Person’) to display its attributes. Choose the appropriate attribute (for example, Gender) and click ‘OK’
  7. Choose which value of the attribute you want to use for the condition. For this example, keep the first new box as ‘equals value’ and change the second new box to ‘Male’
  8. Select ‘Run Query’

The Coding Query page that appears in the Details View.

The results of the coding query will then be displayed underneath in a series of tabs, as they are for a code. If you want to keep a copy of your coding query, you can choose either ‘Save Results…’ or ‘Save Criteria…’.

For this example, it would be appropriate to select ‘Save Results…’ and save the results as a sub-code of the Infrastructure code. To do this, click ‘Select…’, click on the plus sign next to the Codes folder, select the Infrastructure code and select ‘OK’. The new code will then be stored with your existing codes as a sub-code of the Infrastructure code.

Matrix coding queries

You can use matrix coding queries to make comparisons and look for patterns in your data. They allow you to compare how much and what content has been coded at the intersections of different codes, or for different cases and codes. For example, you can compare positive and negative attitudes towards four different issues in the sample project by finding content that has been coded at the intersection of these codes. To do this, follow these steps:

  1. Select Query Criteria in the Navigation View (in the ‘Queries’ group), then right click in the white space in the List View and select ‘New Query’ and ‘Matrix Coding Query’. Alternatively, select the ‘Explore’ tab on the ribbon at the top of the screen, then select ‘Matrix Coding Query’
  2. Choose where you would like to search. The default is ‘Files & Externals’, but if you would like to search specific items or folders, click on the appropriate button and make your selections in the dialog box that appears. You can also filter the query as described for text search queries
  3. Choose what you would like displayed in the rows of the matrix by clicking on the ‘+’ sign underneath the ‘Rows’ box. For this example, choose ‘Select Items…’, then click on ‘Codes’ to view the available codes. Tick Balance, Community change, Economy and Infrastructure, then click ‘OK’. The selected codes will appear as rows in the matrix. If you decide that you do not want to include one of them, select it and click the ‘-‘ sign
  4. Choose what you would like displayed in the columns by clicking on the ‘+’ sign underneath the ‘Columns’ box. For this example, choose ‘Select Items…’, then click on ‘Codes’ and click on the plus sign next to the Attitude code. Tick Negative and Positive, then click ‘OK’. The selected codes will appear as columns in the matrix. Again, if you decide that you do not want to include one of them, select it and click the ‘-‘ sign
  5. When you are happy with your selections, choose ‘Run Query’

Once the matrix has been created, you can double click on any intersection (cell) to view the content that has been coded there. You can also use the appropriate cell shading option on the ribbon to colour the matrix according to which intersections have the most and least coding. To keep a copy of the matrix, choose ‘Save Results…’ or ‘Save Criteria…’.

Crosstab queries

Like a matrix coding query, a crosstab query allows you to make comparisons and look for patterns in your data. The two types of queries are very similar and can be used in similar ways. However, a crosstab query is particularly useful when you want to compare codes across different values of a classification attribute. For example, you can compare how often people from different townships responded to four different issues in the sample project as follows:

  1. Select Query Criteria in the Navigation View (in the ‘Queries’ group), then right click in the white space in the List View and select ‘New Query’ and ‘Crosstab’. Alternatively, select the ‘Explore’ tab on the ribbon at the top of the screen, then select the ‘Queries’ drop-down menu and choose ‘Crosstab’
  2. Choose where you would like to search. The default is ‘Files & Externals’, but if you would like to search specific items or folders, click on the appropriate button and make your selections in the dialog box that appears. You can also filter the query as described for text search queries
  3. Keep ‘Crosstab codes against’ as ‘Attributes’. You can change this to ‘Cases’ if you want to compare different cases instead of attribute values
  4. Click on the ‘+’ sign underneath the ‘Codes’ box to choose what you would like displayed in the rows of the table. For this example, tick Balance, Community change, Economy and Infrastructure, then click ‘OK’
  5. Keep the ‘Classification’ as ‘Person’ and ‘Attribute1’ as Township
  6. When you are happy with your selections, choose ‘Run Query’

Once the table has been created, you can double click on any intersection (cell) to view the content that has been coded there. You can also use the appropriate cell shading option on the ribbon to colour the table according to which intersections have the most and least coding. To keep a copy of the table, choose ‘Save Results…’ or ‘Save Criteria…’.