I have a database and over one million records in it. I want to get the same number of records from the database for 3 different conditions. I am currently using code that performs 3 MySQL queries. I wonder if there is a possibility to get the same result using one SELECT query?.
The following code select an equal number of 20 records for each site=X condition.
<?php
/*---------*/
$db1 = mysqli_query($connect, "SELECT * FROM news WHERE site='1' ORDER BY id DESC LIMIT 0,20");
$db2 = mysqli_query($connect, "SELECT * FROM news WHERE site='2' ORDER BY id DESC LIMIT 0,20");
$db3 = mysqli_query($connect, "SELECT * FROM news WHERE site='3' ORDER BY id DESC LIMIT 0,20");
/*------------*/
?>