INSERT INTO `prices` (`id`, `file`, `price`) VALUES
(1, 1, 84.99),
(2, 1, 80.99),
(3, 2, 3981.27)
SELECT RAND( MIN(price), 2) AS price FROM prices
SELECT id, RAND( MIN(price), 2) AS price FROM prices
SELECT
qc.id,
pr.name AS producer,
qc.model,
qc.modification,
qc.other_info,
prc.id,
ROUND(MIN(prc.price),2) AS price
FROM
`quadrocopter` qc
INNER JOIN `producer` pr ON pr.id = qc.producer
INNER JOIN `price` prc ON prc.copter_id = qc.id
where
exists (
select
*
from
copter_answer c
where
c.copter_id = qc.id
AND c.answer = 1
) && exists (
select
*
from
copter_answer c
where
c.copter_id = qc.id
AND c.answer = 2
) && prc.price > 1000 && prc.price < 1500
GROUP BY
prc.copter_id
ORDER BY
qc.id DESC
SELECT
qc.id,
pr.name AS producer,
qc.model,
qc.modification,
qc.other_info,
ROUND( MIN(prc.price), 2) AS price
FROM `quadrocopter` qc
INNER JOIN `producer` pr
ON pr.id = qc.producer
INNER JOIN `price` prc
ON prc.copter_id = qc.id
where
exists (select * from copter_answer c where c.copter_id = qc.id AND c.answer = 1)
&& exists (select * from copter_answer c where c.copter_id = qc.id AND c.answer = 2)
&& prc.price > 1000
&& prc.price < 1500
GROUP BY prc.copter_id
ORDER BY qc.id DESC