Selecting images from Lightroom's database with SQL

Posted: (EET/GMT+2)

 

Adobe's Lightroom uses SQLite as the database engine. That said, the file "Lightroom Database.lrdb" is simply a SQLite 3 database, and by using a SQLite browser, you can easily execute SQL queries againts the database. Here's an example:

SELECT f.absolutePath
FROM AgLibraryTag t, AgLibraryTagImage i, Adobe_imageFiles f
WHERE (t.name = "John Doe") AND (t.kindName = "AgKeywordTagKind")
AND (i.tag = t.id_local) AND (i.image = f.image)

This query would fetch the absolute paths of all images which have been tagged with the tag "John Doe". As you can see, there are three tables that are related to each other with the "id_local" field, and are thus part of the join. As you can see, Lightroom's database isn't a black box. :-) Great!