jeudi 28 mars 2019

SQLite random nested query sometimes doesn't return result

I have two tables, a and b, connected by a many-to-many relational table, c. For the needs of my program, I need 5 unique, random results.

First, I create a temporary table by randomly selecting one of the rows (varA) from table a. I create another temporary table by randomly selecting from table b one of the rows that is related to varA by table c (var1). I create a third temporary table by randomly selecting another row from table b related to varA that isn't var1 (var2). I then want to randomly select a row from table a that's related to var1 by table c that isn't varA (varZ). Finally, I want to randomly select a row from table a that's related to var2 by table c that is neither varA or varZ (varY).

Hopefully that was followable.

With what I have, sometimes it only returns once or even zero results. How do I always ensure that there's a result?

Alternatively, if there's a more elegant way to do this, I'm all ears. Or eyes, because I'll be reading it...




Aucun commentaire:

Enregistrer un commentaire