I have a table:
CREATE TABLE `test` (
`id` int(11) NOT NULL,
`pn` varchar(40) NOT NULL,
`price` int(1) NOT NULL,
`company` varchar(30) NOT NULL,
`flag` varchar(1) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
What I want to do is to find cheapest goods (pn) and I've managed to do it:
SELECT DISTINCT min(price), pn, company FROM `test` GROUP BY pn
But how I can also mark cheapest goods with flag. I want for all the results Update tabel, set flag=1. How to do that? Is it possible to use UPDATE table with SELECT DISTINCT?
Here is a SQL Fiddle: http://sqlfiddle.com/#!9/ea1b3f/9