Last active
August 30, 2020 17:49
-
-
Save ShahOdin/a38142853fe189161ee548ae7e8009c3 to your computer and use it in GitHub Desktop.
returns the full row for "highest" record of some sort
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE link ( | |
ID serial PRIMARY KEY, | |
name VARCHAR (255) NOT NULL, | |
other VARCHAR (255) NOT NULL, | |
score INT NOT NULL | |
); | |
INSERT INTO link (name, other, score) | |
VALUES | |
('Foo', 'ABC' , 13), | |
('Foo', 'DEF', 14), | |
('Baz', 'JKL', 12), | |
('Baz', 'MNO', 10) | |
; | |
SELECT i1.name, i1.other, i1.score AS "MAX SCORE" | |
FROM link AS i1 LEFT JOIN link AS i2 | |
ON (i1.name = i2.name AND i1.score < i2.score) | |
WHERE i2.score IS NULL | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://sqlfiddle.com/#!9/7f4d4b/1/0