Answer the question
In order to leave comments, you need to log in
How to pull out the id of the field from where the MIN value will be pulled out?
Something like this table
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
Answer the question
In order to leave comments, you need to log in
Just put the id in the output list..
Try like this:
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question