# Search for label not in entry Request

**URL:** <https://discuss.zetetic.net/t/search-for-label-not-in-entry-request/4755>\
**Category:** Codebook\
**Created:** [December 29, 2020, 5:38pm UTC](https://discuss.zetetic.net/t/search-for-label-not-in-entry-request/4755 "2020-12-29T17:38:05Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![lwetzel](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/lwetzel/32/287_2.png) [@lwetzel](https://discuss.zetetic.net/u/lwetzel)\
**Post date:** [December 29, 2020, 5:38pm UTC](https://discuss.zetetic.net/t/search-for-label-not-in-entry-request/4755/1 "2020-12-29T17:38:05Z")

</div>

Is it possible that one might do a search that will return results for a NOT query?  
I have a Label called “Validated”. I have a large number of entries and I am trying to validate that everything is correct in my data. I can’t find a way to find entries that do not contain the “Validated” label. It would be nice to be able to do a search for entries that the “Validated” label is not in.

Hope that’s clear

---

<div class="post-metadata">

**Author:** ![mmoore](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/mmoore/32/858_2.png) [@mmoore](https://discuss.zetetic.net/u/mmoore)\
**Post date:** [January 5, 2021, 7:42pm UTC](https://discuss.zetetic.net/t/search-for-label-not-in-entry-request/4755/2 "2021-01-05T19:42:16Z")

</div>

Hey @lwetzel

Thanks for using Codebook and posting to the discussion forum with this question.

It isn’t currently possible to perform advanced search queries (such as NOT) directly within the Codebook search bar, although improving the search capability to be more flexible and include some of these advanced query capabilities is something that we have considered in the past and may be nice to include in Codebook in the future.

One recommendation I do have which would work currently is using a program called [DB Browser for SQLite](https://sqlitebrowser.org) to open and query your encrypted Codebook database.

**Disclaimer: Don’t modify your Codebook database outside of the Codebook interface as changes will not be picked up by Codebook’s tracking mechanism and won’t propagate to other copies of Codebook when syncing. The query in these steps only reads from the encrypted Codebook database which is safe to do**

Here are the steps:

1. Download the latest version of DB Browser for SQLite using the Download tab from the page linked above. Install it on your system.
2. Launch DB Browser for SQLite and access File menu \> Open Database, open your `strip.db` encrypted Codebook database file at the location [1] – Enter your Codebook Master Password when prompted.
3. Once your encrypted database opens, select the Execute SQL tab near the top of the window. Paste this query in the text box and click the “play button” to execute the query:

_This query is incorrect, see below for the corrected query: [Search for label not in entry Request - #7 by mmoore](https://discuss.zetetic.net/t/search-for-label-not-in-entry-request/4755/7)_

```auto
SELECT DISTINCT(name) FROM entries e
INNER JOIN fields f ON f.entry_id = e.id
WHERE f.type_id <> (SELECT id FROM types WHERE name = 'Validated')

```

1. This will provide you with a list of Entry names which don’t have a `Validated` label present. If you’d prefer you can export the results from he query within DB Browser for SQLite to a CSV by following the steps here: [Save query results as csv - #3 by justinclift](https://discuss.zetetic.net/t/save-query-results-as-csv/2343/3)

[1] Codebook encrypted database locations:

### Windows:

`%APPDATA%\Zetetic LLC\Strip\strip.db`

### macOS:

`~/Library/Group Containers/PD7G6HRMGV.net.zetetic.STRIP/Strip/strip.db`

---

<div class="post-metadata">

**Author:** ![lwetzel](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/lwetzel/32/287_2.png) [@lwetzel](https://discuss.zetetic.net/u/lwetzel)\
**Post date:** [January 5, 2021, 9:26pm UTC](https://discuss.zetetic.net/t/search-for-label-not-in-entry-request/4755/3 "2021-01-05T21:26:22Z")

</div>

Thanks for the reply Micha.

Does the query return records that contain the field ‘Validated’? If so how do I change it to return only records that don’t have the field ‘Validated’ at this point?

---

<div class="post-metadata">

**Author:** ![mmoore](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/mmoore/32/858_2.png) [@mmoore](https://discuss.zetetic.net/u/mmoore)\
**Post date:** [January 5, 2021, 9:42pm UTC](https://discuss.zetetic.net/t/search-for-label-not-in-entry-request/4755/4 "2021-01-05T21:42:32Z")

</div>

> [@lwetzel](#):
>
> Does the query return records that contain the field ‘Validated’? If so how do I change it to return only records that don’t have the field ‘Validated’ at this point?

The query above will return the Entry names which **do not** have a field which uses the Validated label.

---

<div class="post-metadata">

**Author:** ![lwetzel](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/lwetzel/32/287_2.png) [@lwetzel](https://discuss.zetetic.net/u/lwetzel)\
**Post date:** [January 5, 2021, 10:05pm UTC](https://discuss.zetetic.net/t/search-for-label-not-in-entry-request/4755/5 "2021-01-05T22:05:53Z")

</div>

It is returning a mixture of both those that do and those that don’t.

---

<div class="post-metadata">

**Author:** ![mmoore](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/mmoore/32/858_2.png) [@mmoore](https://discuss.zetetic.net/u/mmoore)\
**Post date:** [January 5, 2021, 10:14pm UTC](https://discuss.zetetic.net/t/search-for-label-not-in-entry-request/4755/6 "2021-01-05T22:14:34Z")

</div>

@lwetzel

A couple of additional questions:

- Do you have more than one label with the name “Validated” in your Codebook database?
- Can you re-create a test Entry structure with sample data (and screen shot it) which is improperly returning in the query?

Edit: Apologies, let me modify the query, I was just able to reproduce it. Give me another minute.

---

<div class="post-metadata">

**Author:** ![mmoore](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/mmoore/32/858_2.png) [@mmoore](https://discuss.zetetic.net/u/mmoore)\
**Post date:** [January 5, 2021, 10:33pm UTC](https://discuss.zetetic.net/t/search-for-label-not-in-entry-request/4755/7 "2021-01-05T22:33:46Z")

</div>

@lwetzel

Can you give this query a try:

```auto
SELECT e.name FROM entries e WHERE e.type != '1' AND e.id NOT IN
(SELECT f.entry_id FROM fields f WHERE f.type_id = (SELECT id FROM types t WHERE t.name = 'Validated'))

```

I believe that should do it. Let me know the results.

---

<div class="post-metadata">

**Author:** ![lwetzel](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/lwetzel/32/287_2.png) [@lwetzel](https://discuss.zetetic.net/u/lwetzel)\
**Post date:** [January 5, 2021, 10:39pm UTC](https://discuss.zetetic.net/t/search-for-label-not-in-entry-request/4755/8 "2021-01-05T22:39:13Z")

</div>

Yes. That looks like a better return. Those I checked were indeed the records I need.

Thanks

---

<div class="post-metadata">

**Author:** ![mmoore](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/mmoore/32/858_2.png) [@mmoore](https://discuss.zetetic.net/u/mmoore)\
**Post date:** [January 5, 2021, 10:41pm UTC](https://discuss.zetetic.net/t/search-for-label-not-in-entry-request/4755/9 "2021-01-05T22:41:45Z")

</div>

Excellent. Glad I could help and sorry for the misstep there on the initial query. We’ll continue to discuss/consider improvements to the search mechanism within Codebook itself for the future. In the mean time, feel free to reach out again if you have any other questions or feedback.

---

<div class="post-metadata">

**Author:** ![lwetzel](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/lwetzel/32/287_2.png) [@lwetzel](https://discuss.zetetic.net/u/lwetzel)\
**Post date:** [January 10, 2021, 10:47pm UTC](https://discuss.zetetic.net/t/search-for-label-not-in-entry-request/4755/10 "2021-01-10T22:47:01Z")

</div>

Hello, again Micah,

Ok so just to take this a step further what would be the query that would get me results that show that the names of entries where the field with “Validated” label does not contain “yes”?

---

<div class="post-metadata">

**Author:** ![mmoore](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/mmoore/32/858_2.png) [@mmoore](https://discuss.zetetic.net/u/mmoore)\
**Post date:** [January 11, 2021, 3:49pm UTC](https://discuss.zetetic.net/t/search-for-label-not-in-entry-request/4755/11 "2021-01-11T15:49:03Z")

</div>

Hey @lwetzel

No problem. This adjustment to the query should do it I believe:

```auto
SELECT e.name FROM entries e WHERE e.type != '1' AND e.id NOT IN
(SELECT f.entry_id FROM fields f WHERE f.type_id = (SELECT id FROM types t WHERE t.name = 'Validated') AND f.value = 'yes' COLLATE NOCASE)

```

This will return entry names where one of the following is true:

1. They have no field present with a Validated label.
2. They have a field with a Validated label, but no value in it.
3. They have a field with a Validated label with a value, but the value isn’t `yes` (case insensitive)

Let me know if that does the trick. Thanks!

---

<div class="post-metadata">

**Author:** ![lwetzel](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/lwetzel/32/287_2.png) [@lwetzel](https://discuss.zetetic.net/u/lwetzel)\
**Post date:** [January 12, 2021, 4:10pm UTC](https://discuss.zetetic.net/t/search-for-label-not-in-entry-request/4755/12 "2021-01-12T16:10:44Z")

</div>

Yes Micah,

The query is working fine. Wish I know the Query language so that I could break each out separately but, it is finding what I need.

Thanks a bunch.
