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.
CREATE TABLE abc (id INT, name CHAR(4), place CHAR(5));
INSERT INTO abc VALUES
( 1 , 'asd1' , 'abcd1' ),
( 2 , 'asd2' , 'abcd1' ),
( 3 , 'asd1' , 'abcd2' ),
( 4 , 'asd3' , 'abcd1' ),
( 5 , 'asd4' , 'abcd1' ),
( 6 , 'asd1' , 'abcd1' ),
( 7 , 'asd2' , 'abcd2' ),
( 8 , 'asd3' , 'abcd2' ),
( 9 , 'asd4' , 'abcd2' ),
( 10 , 'asd3' , 'abcd1' ),
( 11 , 'asd4' , 'abcd1' ),
( 12 , 'asd4' , 'abcd2' ),
( 13 , 'asd1' , 'abcd2' );
SELECT * FROM abc;
id name place
1 asd1 abcd1
2 asd2 abcd1
3 asd1 abcd2
4 asd3 abcd1
5 asd4 abcd1
6 asd1 abcd1
7 asd2 abcd2
8 asd3 abcd2
9 asd4 abcd2
10 asd3 abcd1
11 asd4 abcd1
12 asd4 abcd2
13 asd1 abcd2
SELECT t1.*
FROM abc t1
JOIN ( SELECT MAX(id) id, name
FROM abc
GROUP BY name ) t2 ON t1.id = t2.id AND t1.name = t2.name;
id name place
7 asd2 abcd2
10 asd3 abcd1
12 asd4 abcd2
13 asd1 abcd2