List notes with same value from another key

  • I would like dataview to list notes with ANY of the values in “wfrom” that occur in another notes’ “strongs” value.

I’ve tried so many things…

This is what I have right now,

LIST
FROM #dictionary  
WHERE contains(strongs, this.wfrom) AND file.name != this.file.name AND !startswith(file.path, "Tools & Guides/")

I’m assuming the wfrom is within the file where the query resides, and then what you’d like to do is something like:

```dataview
LIST
FROM #dictionary
WHERE contains(this.wfrom, strongs) AND file != this.file
```

That should handle the case if strongs always holds a single value. If strongs can hold multiple values occasionally, you need to do it another way:

```dataview
LIST
FROM #dictionary
WHERE file != this.file
  AND any(map( flat(list(strongs)), (s) => contains(this.wfrom, s) ))
```

Here we first map whether any of the candidates in strongs is found in wfrom, and then we check if there was any() match in that list.

  • Yes ‘strongs’ always hold just one value
  • ‘wfrom’ can hold multiple values.

I tried your first query, it did shorten the list but it is still adding extra notes in the list. The only one that contains a value from ‘wfrom’ in this case is the “power” note. So the power note should be the only one listed here. I’m not sure what I’m doing wrong.

Thank you for your help.

Then it’s time for a little intermediate debug table, please try the following:

```dataview
TABLE strongs, contains(this.wfrom, strongs), this.wfrom
FROM #dictionary
WHERE file != this.file AND contains(this.wfrom, strongs)
LIMIT 20
```

What does this query return? Does that give you any clue on what’s happening?

It shows most of the notes listed as false, the only one that show true under contains(this.wfrom, strongs) is the power note, which is in fact the case.

I do see that strongs H8280 shows under all the notes, but they are definitely not in those notes. That’s odd.

Updated: I don’t understand the last column…

That column should repeat, but what is shown in the column in front of the true/false column?

But it’s still very strange that it shows any rows with false at all… But maybe that third line to the last shows the issue with the multiple values…

What happens if you do any(contains(this.wfrom, strongs)) in that table query (in both places)?

I updated the previous reply, but I would also like to get an assurance that you do use these queries as shown, and don’t do any GROUP BY or similar in addition to the query as shown?

I’m sorry, I don’t understand what you mean by both places.

This is what is shows with the

any(contains(this.wfrom, strong))

at the top.

Yes, I am using the queries given, as is.

If you look at the last (clipped) line of that image, you see that it reports two entries for the “god” file in the third column. This indicates that by some reason the contains(this.wfrom, strongs) returns a list of values, which is considered a true statement in most cases. However, with the modification in the last column, we see it only reports the one false which it should.

So I’m not sure why this happens in your case, it could be related to the type of the wfrom property, but I reckon that the following query should start producing the wanted result:

```dataview
LIST
FROM #dictionary
WHERE any(contains(this.wfrom, strongs)) AND file != this.file
```

By the way, you said strongs only holds one value, but the god file shows multiple values, so you might need to use the second variant of the query in my original post anyways! Or possibly this variant:

```dataview
LIST
FROM #dictionary
WHERE file != this.file
  AND any(map( flat(list(strongs)), (s) => any(contains(this.wfrom, s)) ))
```
1 Like

YAY!!! The second one worked.
And Yes, my apologies, I forgot that sometimes I do add the Greek and the Hebrew strongs in one note. I don’t do it often so I had forgotten.

Thank you very much for your help!!

image

1 Like

Just a little more explanations on that second variant, and that is that the flat(list(strongs)) converts any single values into a list of one values (through the list( ... )), and multiple values first into a list of list of values. Since we don’t want a list of lists, the flat( ... ) removes the outer lists. The net effect is that with this construct we always get a list of all the values of strongs.

This list then allows us to map( ... ) each of those values (or just the one) to check against the this.wfrom() list. And finally we check that mapped list of values if any() of them are found to be true.

For the prosperity, you hopefully also learned how you can change your query into a TABLE and just repeats the different WHERE clauses in order to see which has the anticipated values or not. I’ve for sure got a lot of help of doing those kind of intermediate tables to help me figure out what is really happening.

1 Like

Thank you, that is what I have been attempting to figure out how to get it to make the listed values for months and I couldn’t find an answer as to how to do it.

Also, I did find it pretty cool how the TABLE listed everything like that.

Thank you for explaining how everything works as well!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.