{"id":3342,"date":"2015-04-28T14:31:39","date_gmt":"2015-04-28T13:31:39","guid":{"rendered":"http:\/\/positech.co.uk\/cliffsblog\/?p=3342"},"modified":"2015-04-28T14:31:39","modified_gmt":"2015-04-28T13:31:39","slug":"sql-headache","status":"publish","type":"post","link":"https:\/\/www.positech.co.uk\/cliffsblog\/2015\/04\/28\/sql-headache\/","title":{"rendered":"SQL headache"},"content":{"rendered":"<p>Gah, I spent all morning wracking my brains to fix a rendering order batching bug (fixed! yay!), and now I suddenly have a second daily headache with some SQL. If you use SQL a lot you can probably tell me how trivial this is&#8230;<\/p>\n<p>Imagine a table of scores<\/p>\n<p>Dave\u00a0 PlanetA 4,200<\/p>\n<p>Mike PlanetB 2,200<\/p>\n<p>Dave PlanetA 4,100<\/p>\n<p>Chas Planet A, 7,200<\/p>\n<p>And so on. What I am doing right now is a SELECT to get the top 20 rows from this table where the planet is (for example ) PlanetA. What I *want*n to do is to get the top 20 rows, but only the TOP entry for each player. So you only appear once in each high score list.<\/p>\n<p>I can&#8217;t get my head around how to do that. I want something like SELECT * FROM scores WHERE scores.planet == &#8216;zog&#8217; AND scores.score IS HIGHEST FOR score.player ORDER BY score<\/p>\n<p>But of course I&#8217;ve made that syntax up and its imaginary. Albeit cool.<\/p>\n<p>Tell me there is an easy way to do this thang?<\/p>\n<p>And ooh guest what! Democracy 3 is the #1 strategy game on the ipad right now, due to a rather insane price drop I&#8217;m experimenting with&#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Gah, I spent all morning wracking my brains to fix a rendering order batching bug (fixed! yay!), and now I suddenly have a second daily headache with some SQL. If you use SQL a lot you can probably tell me how trivial this is&#8230; Imagine a table of scores Dave\u00a0 PlanetA 4,200 Mike PlanetB 2,200<\/p>\n<p class=\"text-right\"><span class=\"screen-reader-text\">Continue Reading&#8230; SQL headache<\/span><a class=\"btn btn-secondary continue-reading\" href=\"https:\/\/www.positech.co.uk\/cliffsblog\/2015\/04\/28\/sql-headache\/\">Continue Reading&#8230;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-3342","post","type-post","status-publish","format-standard","hentry","category-programming"],"_links":{"self":[{"href":"https:\/\/www.positech.co.uk\/cliffsblog\/wp-json\/wp\/v2\/posts\/3342","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.positech.co.uk\/cliffsblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.positech.co.uk\/cliffsblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.positech.co.uk\/cliffsblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.positech.co.uk\/cliffsblog\/wp-json\/wp\/v2\/comments?post=3342"}],"version-history":[{"count":1,"href":"https:\/\/www.positech.co.uk\/cliffsblog\/wp-json\/wp\/v2\/posts\/3342\/revisions"}],"predecessor-version":[{"id":3343,"href":"https:\/\/www.positech.co.uk\/cliffsblog\/wp-json\/wp\/v2\/posts\/3342\/revisions\/3343"}],"wp:attachment":[{"href":"https:\/\/www.positech.co.uk\/cliffsblog\/wp-json\/wp\/v2\/media?parent=3342"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.positech.co.uk\/cliffsblog\/wp-json\/wp\/v2\/categories?post=3342"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.positech.co.uk\/cliffsblog\/wp-json\/wp\/v2\/tags?post=3342"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}