add batch remove batch split batch comment selection show hidden batches hide batch highlight batch
db<>fiddle
donate feedback about
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
SET SESSION sql_mode := '';

CREATE TABLE `experience` (
`id` int(11) NOT NULL,
`resume_id` varchar(9) DEFAULT NULL,
`company_name` varchar(12) DEFAULT NULL,
`start_date` date DEFAULT NULL,
`end_date` date DEFAULT NULL,
`present` varchar(7) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT INTO `experience`
(`id`, `resume_id`, `company_name`, `start_date`, `end_date`, `present`) VALUES
(1, '1', 'abc', '2009-01-01', '2009-12-31', '0'),
(2, '1', 'def', '2010-01-01', '2012-12-31', '0'),
(3, '1', 'ghi', '2013-01-01', '0000-00-00', '1'),
(4, '2', 'abc', '2009-01-01', '2009-12-31', '0'),
(5, '2', 'def', '2010-01-01', '2012-12-31', '0'),
(6, '2', 'ghi', '2013-01-01', '2016-01-01', '0'),
(7, '3', 'abc', '2009-01-01', '2009-12-31', '0'),
(8, '3', 'def', '2017-01-01', '0000-00-00', '1'),
(9, '3', 'ghi', '2010-01-01', '0000-00-00', '1');

ALTER TABLE `experience`
ADD PRIMARY KEY (`id`);

SELECT * FROM experience;
id resume_id company_name start_date end_date present
1 1 abc 2009-01-01 2009-12-31 0
2 1 def 2010-01-01 2012-12-31 0
3 1 ghi 2013-01-01 0000-00-00 1
4 2 abc 2009-01-01 2009-12-31 0
5 2 def 2010-01-01 2012-12-31 0
6 2 ghi 2013-01-01 2016-01-01 0
7 3 abc 2009-01-01 2009-12-31 0
8 3 def 2017-01-01 0000-00-00 1
9 3 ghi 2010-01-01 0000-00-00 1
SELECT t1.*
FROM experience t1
JOIN ( SELECT resume_id,
MAX(start_date + INTERVAL 1000 * present YEAR) start_date
FROM experience t2
GROUP BY resume_id ) t3 USING (resume_id)
WHERE t1.start_date + INTERVAL 1000 * t1.present YEAR = t3.start_date;
id resume_id company_name start_date end_date present
3 1 ghi 2013-01-01 0000-00-00 1
6 2 ghi 2013-01-01 2016-01-01 0
8 3 def 2017-01-01 0000-00-00 1