I have Database table called tbl_emails like this
id email
1 [email protected]
2 [email protected]
3 [email protected]
4 [email protected]
5 [email protected]
6 [email protected]
7 [email protected]
8 [email protected]
9 [email protected]
10 [email protected]
I have about 5000 rows in the table. Now What I am looking to do is get 100 emails from it. But I want 80 rows means 80% DESC and 20% ASC by id, currently I am doing it by multiple queries and merging result in PHP. I am wondering its possible in single SQL query?
Thanks!
2
Answers
You can use UNION ALLto join the results of 2 queries with the same columns.
If you need to preserve order of the rows in the ouput, you can in addition use variables to store the row count in each query
use the UNION ALL operator to combine the results of two separate queries that retrieve the required percentages of emails.
let me know if this can help you