N
N
Neuro2019-06-12 15:01:21
PostgreSQL
Neuro, 2019-06-12 15:01:21

How to add data from table A to table B postgreSQL?

I have 2 tables:
sensor_instances table

spoiler
5d00e61cbadd0805841890.png

and sensor_alerts table
spoiler
5d00e65b4ee30768316312.png

I can't figure out how to make an SQL query to get the sensor_alerts table with the addition of the location column from sensor_instances to it?
and it is necessary that locations be assigned to the lines sensor_alerts.sensorid = sensor_instances.id
tried such an entry, but in the end I get only location
SELECT location FROM sensor_instances LEFT JOIN sensor_alerts ON sensor_instances.id = sensor_alerts.sensorid

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Tsvetkov, 2019-06-12
@Riveran

SELECT sensor_alerts.*, sensor_instances.location 
FROM sensor_instances 
  LEFT JOIN sensor_alerts ON sensor_instances.id = sensor_alerts.sensorid
first 20 lines
LIMIT and OFFSET or FETCH .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question