There is a table. It is necessary to make a request to it and return at least 5 entries under certain conditions. If there are no 5 records in the table that satisfy the specified conditions, it is necessary to return those records that satisfy the condition (for example, 3 records), and 2 more records with some fixed data (numeric fields 0, string - empty lines).
Example. Table table
| INT id | INT data | VARCHAR str_data | INT status | ----------------------------------------------------- | 1 | 123 | "qwert" | 1 | ----------------------------------------------------- | 2 | 343 | "zzzzz" | 1 | ----------------------------------------------------- | 3 | 923 | "qweq" | 2 | ----------------------------------------------------- | 4 | 843 | "qdfgrt" | 2 | ----------------------------------------------------- | 5 | 763 | "qddftp" | 1 | -----------------------------------------------------
Required query (SELECT data, str_data, status FROM table WHERE status = 1)
, which returns the following:
| INT data | VARCHAR str_data | INT status | -------------------------------------------- | 123 | "qwert" | 1 | -------------------------------------------- | 343 | "zzzzz" | 1 | -------------------------------------------- | 763 | "qddftp" | 1 | -------------------------------------------- | 0 | "" | 0 | -------------------------------------------- | 0 | "" | 0 | --------------------------------------------
The only thing that comes to mind is to keep in table 5 "zero" entries (last 2 lines), but this option is not pleasant.