If I understand your request correctly, it would be something like this:
B4X:
sql1.Initialize(my_path, "my_tags.db", False)
Dim rs As ResultSet
Dim str As String="xxx"
rs = sql1.ExecQuery2("SELECT key FROM tags WHERE person=1 AND key<>?", Array(str))
Or better:
B4X:
Dim str As String="xxx"
Dim person as int = 1
rs = sql1.ExecQuery2("SELECT key FROM tags WHERE person=? AND key<>?", Array(person, str))
If I understand your request correctly, it would be something like this:
B4X:
sql1.Initialize(my_path, "my_tags.db", False)
Dim rs As ResultSet
Dim str As String="xxx"
rs = sql1.ExecQuery2("SELECT key FROM tags WHERE person=1 AND key<>?", Array(str))
Or better:
B4X:
Dim str As String="xxx"
Dim person as int = 1
rs = sql1.ExecQuery2("SELECT key FROM tags WHERE person=? AND key<>?", Array(person, str))
Just to clarify.
My line would exclude only records where key is exactly str
Mahares' line would exclude any record where the key contains str
Depending on what you need, use one or the other
Dim str As String "Sergey"
rs = SQL1.ExecQuery2("SELECT key FROM tags WHERE person= ? and key NOT LIKE ? LIMIT 1", Array As Object(1, $"%${str}%"$))
Please note that the code I posted also excludes the EXACT search and also besides anywhere in the column.
If you use JCO's code the query will be: "SELECT key FROM tags WHERE person=? AND key<>? LIMIT 1"
If for instance, you have 5 that do not match, it will only show the first of the 5 records. That is how I understood the question. If not, please explain, preferably with an example. Added this: If you have keyx that have a empty string and you want to display it, as the first one, add this to the query: before LIMIT 1:
ORDER BY keyx LIMIT 1
There are ways to improve performance of queries. If you have one DB that is giving you trouble in terms of performance and you are receptive to post it or its project and show what slows it down, I am sure members will take a stab at it and report back to you.