Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to combine three tables data to retrieve a data

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading