cancel
Showing results for 
Search instead for 
Did you mean: 

SQL query to find if multiple instances of a keyword exist

Timothy_Shepler
Champ on-the-rise
Champ on-the-rise

I am looking for a SQL query to search for if multiple instances of a keyword exist.

2 ACCEPTED ANSWERS

Brad_Phillips
Confirmed Champ
Confirmed Champ

Tim,

Here's an example of me accomplishing this on my test system.  You will need to change the names of the table and columns, but the logic is the same:

select keyvaluesmall, count(*)
From hsi.keyitem102
group by keyvaluesmall
having count(*) >= 2

View answer in original post

Scott_Hirsch
Star Contributor
Star Contributor

If you are using MIKGs, and you want to check for MIKG instances, you will need to check the hsi.keyrecorddata### table.  Here is an example I did in my test system for a Document Type with a MIKG on it to find if there was multiple instances of a MIKG on it (basically Multiple Instances of a KW assuming all keywords are filled in on the MIKG):

select COUNT(itemnum) AS "# of MIKG Instances", itemnum
from hsi.keyrecorddata134
group by itemnum
having COUNT(itemnum) >1

This would give you a result of itemnums that have more than one instance of that particular MIKG, and how many instances there are.

 

* One thing to remember is that if you are using MIKG with a particular keyword, the Settings do not allow you to also have the same Keyword as a loose keyword.

 

Are you looking for MIKGs or Loose Keywords?

View answer in original post

7 REPLIES 7

Scott_Hirsch
Star Contributor
Star Contributor

I have done this in WF with Regular Expressions to count the number of instances before (you could check "if more than 1").  Are you just doing this for a SQL Report?

Brad_Phillips
Confirmed Champ
Confirmed Champ

Tim,

Here's an example of me accomplishing this on my test system.  You will need to change the names of the table and columns, but the logic is the same:

select keyvaluesmall, count(*)
From hsi.keyitem102
group by keyvaluesmall
having count(*) >= 2

It's worth noting that this query assumes that you are looking for multiple instances of a Keyword Type on documents that are only using a standalone or "loose" Keyword Type. You'll need rule out the use of Multi-Instance Keyword Groups (MIKG) before relying on the information found in this query.

This logic was helpful for me. I was trying to find how many documents had +1 instance of a keyword. I just switched the keyvaluesmall for itemnum and it gives you a listing of handles that have +1 instance of the keyword. As it's written above, it will show you keyword values that occur more than once, regardless of which document the instances are attached to.