Question : I have a query that is taking much longer than I expect it should, and I can not […]
Tag: greatest-n-per-group
How to write a query to get wine pairing for a pizza based on pairing weight
Question : I am working on a query to pair drinks to pizzas. Currently I am able to show the […]
Improve query performance of subquery with MAX()
Question : I am looking to migrate our support database from MS SQL Server to Postgres and most of it […]
Single query to get only newest entry of grouped redundant entries
Question : A table files looks like: id, file_name, vendor_id, created 1, z.txt, 2, 2011 2, z.txt, 2, 2011 3, […]
Exists subselect vs inner join?
Question : I’m moving up to the next level of my mystery query. It looks like there’s a subselect inside […]
Better database for “keep always the 5 latest entries per ID and delete older”?
Question : I have a PostgreSQL database with a history table where I store an fooID (not a primary key […]
SELECT DISTINCT ON, ordered by another column
Question : Please consider the following table test: CREATE TABLE test(col1 int, col2 varchar, col3 date); INSERT INTO test VALUES […]
Joining two select statements
Question : Im using MySql 8.0 and I’ve been exercising a lot of quries but this one I cant seem […]
Remove duplicate values from query result
Question : I am using Postgres 9.3.9. I have 2 tables : f_agent : CREATE TABLE f_agent ( f_agent__id bigserial […]
How to select a row based on the maximum value of a column, when ties are expected
Question : SUBSCRIBER DATE TIME VALUE aaa 23-04-2015 04:04:07 10 aab 23-04-2015 12:04:32 5 bbb 23-04-2015 01:04:05 20 bbb 23-04-2015 […]