Skip to content
Advertisement

SQL query for overlapping time [closed]

I have this data:

enter image description here

I’m looking for a query which can return the results of combination of Type (Phone and Memory) based on overlapping of startdate and enddate as below:

enter image description here

Thanks

Advertisement

Answer

Probably something like this:

SELECT * 
FROM 
   table p
   INNER JOIN 
   table m 
   ON 
     NOT(m.startdate > p.enddate OR m.enddate < p.startdate)
WHERE 
  p.Type = 'Phone' AND
  m.Type = 'Memory'
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement