SAMPLE 3 For 9473718

0

Please login or register to vote for this query.

(click on this box to dismiss)

Music Fans Meta

Q&A about the site for music historians, critics, and fans

WITH Ov As (
SELECT 1 as ID, 'Name1' as Name
UNION SELECT 3,    'Name3'
UNION SELECT 4,    'Name4'
UNION SELECT 2,  'Name2'
UNION SELECT 5,    'Name5' )
, St AS (
SELECT 1 as ID, 1 as RelId, 'Set Date 1.1' as Date
UNION SELECT 3, 1, 'Set Date 1.3'
UNION SELECT 4, 2, 'Set Date 2.1'
UNION SELECT 2, 1, 'Set Date 1.2'
UNION SELECT 6, 3, 'Set Date 3.1'
UNION SELECT 5, 2, 'Set Date 2.2'
UNION SELECT 7, 4, 'Set Date 4.1')

SELECT Ov.*, St1.Date
FROM St AS St1
JOIN Ov
  ON Ov.id = St1.RelId
LEFT JOIN St AS St2
  ON St2.id = St1.id
  AND St2.Date > St1.Date
WHERE St2.id IS NULL

Enter Parameters

Options:
Switch to main site
loading Hold tight while we fetch your results