I think I know my Lightroom pretty well, but I couldn't find a way to create a smart collection that returns photos containing only one given keyword. Just one. Say, all photos containing only the 'foo' keyword, no other keywords.

The only solution I found was:

  1. create a smart collection that returns photos containing that given keyword 'foo',
  2. select all photos and add them to another collection (say 'temp') for backup,
  3. remove the given keyword 'foo' from the photos,
  4. create a smart collection that returns the photos containing no keywords: this should return all the photos that only had the 'foo' keyword before I removed it in the previous step. Unfortunately all photos that had no keywords before step 3 will be returned as well, but that's OK, I don't have such photos.
  5. do something with the photos returned by step 4, then go to the 'temp' collection and add the 'foo' keyword back.


  • \$\begingroup\$ I racked my brains but I can't figure out a way to do this; the filtering syntax seems too limited. :-\ \$\endgroup\$ Commented Jan 16, 2011 at 1:52
  • \$\begingroup\$ More digging: It seems that in LR3 there's no way to filter for "contains tags that are not X"; you can only do "does not contain tag X". Without the former, there's no way to achieve what you're looking for. \$\endgroup\$ Commented Jan 16, 2011 at 2:50
  • \$\begingroup\$ Also there's the obvious missing functionality, "keyword equals X" -- you can find keywords containing X, but if you have keywords "peanut" and "peanut butter" you cannot find only the exact match "peanut". \$\endgroup\$
    – Jason S
    Commented Jan 16, 2011 at 15:59

4 Answers 4



I'm sorry, I don't have an answer, I just want to say I wish more tools accepted real SQL as a query language ;)

But technically you can do this. The Lightroom catalog is an SQLite database -- try browsing it with Firefox's SQLite Manager addon, and you'll see it's pretty simple.

You could do this in Lua by writing an extension -- alas, I haven't gone through that step so I'm not sure how to do it.

If you don't need it to be an auto-updating collection the way smart collections work, but rather can deal with running a script every now and then, you could write an external tool to query the SQLite database the way you want, and create a smart collection xml file explicitly including the particular photos in question, and import that into Lightroom. (I needed to do this last bit myself -- see this question)

I just tried this select query and it works great:

    img.id_local AS imageID, 
    kwdef.name AS keyword,
    img.rootFile AS fileID,
 FROM AgLibraryKeywordImage kwimg
 JOIN Adobe_images img
    ON img.id_local = kwimg.image
 JOIN AgLibraryFile files 
    ON img.rootFile = files.id_local
 JOIN AgLibraryKeyword kwdef
    ON kwdef.id_local = kwimg.tag
 GROUP BY kwimg.image
      AND kwdef.name = ?

where you should either replace the ? with a keyword name (e.g. 'foo') or execute as a prepared statement. The GROUP BY clause does the magic: this groups the results by image, HAVING COUNT(*)=1 tells SQL to limit its output to images having 1 record.

This query probably won't work quite right for images that have stacks, in which case it needs to be modified to ensure all the JOINs are one-to-one (except for the keyword-image table)

  • \$\begingroup\$ Yes, you can do that, though I would say the steps I described in my questions are probably simpler, right? Thanks. \$\endgroup\$ Commented Jan 22, 2011 at 6:38
  • \$\begingroup\$ simpler but manual. I have a running grudge against computer software which forces me to repeatedly run through efforts that it could do automatically. \$\endgroup\$
    – Jason S
    Commented Jan 22, 2011 at 16:39

I tried this, in LR 4: keyword contains "mykeyword" AND keyword doesn't contain "abcdfghijklnpqstuvxz"

where the 2nd string is all the letters NOT in "mykeyword"

not perfect, but it's a quick and dirty hack that mostly works.

  • \$\begingroup\$ This was the least worst option for me. I had to put spaces between the alphabet letters to get this to work. \$\endgroup\$
    – alx9r
    Commented Oct 12, 2015 at 1:11
  • \$\begingroup\$ This would get even more tedious than OP's original solution if you've got a situation in which some of these images have lots of keywords other than mykeyword. In that case, you'd have to manually put in all of the keywords that images that have mykeyword also have. \$\endgroup\$ Commented Nov 9, 2020 at 21:00

First, go to All Photographs in your catalog and select all of your photos. In the right pane, under Keywording, you will see a text box below Keyword Tags with ALL keywords found (most followed by an asterisk). Copy all of this text and paste it into a text editor.

Now, remove all of the asterisks (I use find/replace to simplify this), as well as the keyword(s) you wish to limit your search to. Once finished, copy all remaining text.

Now, create a smart collection. Add a rule for "Keyword" "Contains" "Single or Multiple Keyword(s) you want to search".

Next, add a rule for "Keyword" "Does not contain" and paste the edited text. Voila. Adobe really should have thought this one through, but it is Adobe...

  • 1
    \$\begingroup\$ ick. And then have to edit that smart collection every time you add a new keyword. :( \$\endgroup\$
    – cabbey
    Commented Jan 21, 2011 at 7:43
  • 1
    \$\begingroup\$ Interesting, unfortunately doesn't work for me, I have a huge number of keywords. Copying and pasting them into a text editor and saving the file leads to a 45 Kb monster. That's a lot of keywords. Lightroom won't let me enter all of them as a smart collection rule. Interesting idea though, thx. \$\endgroup\$ Commented Jan 22, 2011 at 6:45

In theory you should be able to do this with the "starts with" and "ends with" filters. Basically build it as:

matches ALL  
keyword  starts with  YourOneKeyWord  
keyword  ends with    YourOneKeyWord

But that doesn't seem to be working. :(

  • \$\begingroup\$ does this work now with lightroom 3.4? i have set up a smart collection using "starts with" and "ends with" "flickr", and it is returning only those photos with exactly "flickr", excluding a photo that i had with the dummy keyword "flickrzzz". \$\endgroup\$
    – rapscalli
    Commented Oct 3, 2011 at 23:33
  • \$\begingroup\$ no, even with LR 3.5 this still fails. I'm not sure how but Adobe's definition of "beginsWith" doesn't seem to match the one most folks would use. \$\endgroup\$
    – cabbey
    Commented Oct 12, 2011 at 3:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.