Get data on one MySql request?
There's a table with product data = (title, price).
Can one request make the following: ♪ Receive two goods with a price lower than the current price, - Get two goods with a price higher than the current price.
The price is on the request.
How can you get out?
If I'm not mistaken,'
(SELECT * FROM `product` WHERE `price` > YOUR_PRICE ORDER BY `price` ASC LIMIT 2) UNION (SELECT * FROM `product` WHERE `price` < YOUR_PRICE ORDER BY `price` DESC LIMIT 2)
YOUR_PRICE- Your equal price.
ORDER BY price DESC- You need to take the nearest prices to be compared, or you'll have the lowest.