SAMPLE 3 For 9473718

0

Please login or register to vote for this query.

(click on this box to dismiss)

Philosophy Meta

Q&A about the site for those interested in the study of the fundamental nature of knowledge, reality, and existence

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, St1.ID AS St1ID, St2.ID AS St2ID
FROM St AS St1
JOIN Ov
  ON Ov.id = St1.RelId
LEFT JOIN St AS St2
  ON St2.RelId = St1.RelId
  AND St2.Date > St1.Date
WHERE St2.relid IS NULL

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results