SQL queries using othercallnumber:

TalkHacking LibraryThing

Join LibraryThing to post.

SQL queries using othercallnumber:

1JonathonL88
Edited: Nov 19, 2025, 8:52 pm

1: What flavour of SQL is running at the backend?
2: Why do some SQL queries work whilst others do not. ?
3: What is the single character wild card?

Here are the results of some testing, which may surprise you
using Your books >All Collections > All Fields in Search Your Library

othercallnumber:* ALL NON BLANK entries !!!
othercallnumber:-* ALL BLANK entries !!! NB "-"

Assume two other locations L_SHED and L_ANNEX
othercallnumber: L_ANNEX ALL Books in Annex
othercallnumber: L_SHED ALL Books in Shed
othercallnumber: SHED NO books found, needs complete match on word

Assume Shelves S_01, S_02, S_11
othercallnumber: S* Returns all shelves
othercallnumber: S_0* Returns all except S_11

Cannot find solutions for
Books NOT in Shed
Books NOT in Annex
Books NOT in (Shed or Annex)

Can use othercallnumber: with numeric fields, and for say Borrower of book.

Assume I have two borrowers B_BRIAN and B_SIMON
Simon works in the Legal Department
The entry on one book is othercallnumber: B_SIMON L_LEGAL
and the other is othercallnumber: B_BRIAN

So
othercallnumber: B_BRIAN returns ALL books borrowed by Brian
othercallnumber: L_LEGAL returns all books in the Legal dept
othercallnumber: B* returns all books currently borrowed.

NB Starting each keyword with "_" makes it possible to sort and search by that type.

NB Bookmark successful queries so they can be easily rerun!!

2GraceCollection
Nov 19, 2025, 9:18 pm

>1 JonathonL88: Cannot find solutions for
Books NOT in Shed
Books NOT in Annex
Books NOT in (Shed or Annex)


Have you tried searching ( othercallnumber: NOT "L_SHED" ) ? I'm not quite sure of what the syntax should be for your last query, though. Maybe ( othercallnumber: NOT "L_SHED" OR NOT "L_ANNEX" ).

3JonathonL88
Nov 19, 2025, 9:52 pm

othercallnumber: NOT L_SHED works ok
Search: othercallnumber: -L_SHED x. works ok
Search: othercallnumber: -L_SHED AND -L_ANNEX. works ok

I thought I had tried these...... oh well thanks

4bnielsen
Nov 20, 2025, 3:11 am

>1 JonathonL88: I'm quite sure that all our queries are transformed before becoming sql for the engine behind LT. So as you have discovered it is best to try something and see if it works for you. Another approach is to use the TSV export and then run your own software to find what you want.

5conceptDawg
Nov 21, 2025, 12:25 am

Queries don't use SQL. >4 bnielsen: is correct.
But for the nerds out there, we use ElasticSearch for (most) searches on librarything. So it's not querying using SQL at all.