Fix and Simplify SQL Statements

Closed - This job posting has been filled and work has been completed.

Job Description

This python scripts connects to a postgresql database and retrieves file names for two mutually exclusive alternatives:

- video (if its video, its got to retrieve 3 things (videoname.m4v, videoname.mp4 and videoname.webm)

- picture (if its picture, its got to retrieve 2 things (imagename and imageduration)

Currently this is being done in two separate queries, I want to join them and fix them because there are some rules:
1. server id 0 applies to all servers
2. server id >= applies to an specific server
3. a promo created for an specific server has priority over the "all servers id (0)"
4. The last promo created for an specific server is the one that applies to it

Open Attachment