vendredi 27 novembre 2015

fallback iterative sql queries

I'm looking for a pattern for combining multiple SQL query results with this behavior:

'try query A, if the results are not empty return them '

'if A returned nothing try query B, if the results are not empty return them '

'if B returned nothing try query C, if the results are not empty return them '

'if C returned nothing try query D, if the results are not empty return them '

'if A, B, C, D all returned empty sets, return an empty set'

Any suggestions? I'm aiming for simplicity and performance and while I'm hoping for relatively generic SQL I'm specifically running on sqlite and mysql.

TIA.

Aucun commentaire:

Enregistrer un commentaire