Home > Mobile >  How to combine three tables data to retrieve a data
How to combine three tables data to retrieve a data

Time:01-06

I have the below three tables & its column and want a data as below

Sensor  - SystemID,Sensorname, Sensortime    
User  - EmpID,SystemID    
Incident  -IncID,EmpID,DateOpened,Description

I want to retrieve the sensor data(from Sensor Table) for the EmpID which had Incident.Description field contains word 'System' and Sensor.Sensortime falls 4 days prior to the Incident.DateOpened

Please guide how do I combine these three tables and get this data

CodePudding user response:

WITH two_tables AS(
SELECT * FROM Sensor s JOIN User u
ON s.SystemID = u.SystemID) t
SELECT * FROM Incident i JOIN two_tables on i.EmpID = t.EmpID

This is a rough sketch, you can build on this. Please, try sharing the sql attempt so it can be easier.

  •  Tags:  
  • sql
  • Related