Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL Join and Sorting

MediumSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is SQL Join and Sorting. Start with the requirements and the two tables on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

InMobi campaign reporting combines campaign records with their associated advertisers. Write a PostgreSQL query that joins these two tables and returns the campaign name and advertiser name twice: first in ascending campaign-name order, then in descending campaign-name order.

Requirements

  1. Join inmobi_campaigns to inmobi_advertisers using the advertiser identifier.
  2. Return only campaigns with a matching advertiser.
  3. Produce one ascending result block followed by one descending result block.
  4. Place NULL campaign names last within either sort direction, while retaining matched rows with NULL advertiser names.

Schema

inmobi_campaigns
ColumnTypeDescription
campaign_idPKINTEGERUnique campaign identifier
campaign_nameVARCHAR(150)Campaign name
advertiser_idINTEGERAdvertiser associated with the campaign
inmobi_advertisers
ColumnTypeDescription
advertiser_idPKINTEGERUnique advertiser identifier
advertiser_nameVARCHAR(150)Advertiser name
Tablesinmobi_campaignsinmobi_advertisers
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results