N
N
Neuro2019-06-10 14:13:47
JavaScript
Neuro, 2019-06-10 14:13:47

How to get data from a table?

Good afternoon, tell me how can I write a sql query and get data from table A using data from table B?
There are 2 tables in postgresQL of this type:
Table A

A
5cfe39e09131b282243234.png

Table B
B
5cfe3a0394bc6516282299.png

How can I fetch location data from table A using data from table B?
sensorid from table B is equal to id in table A
as I tried to solve but nothing happened
await app.ds.pg.query(`SELECT location, id FROM A WHERE id IN (${list.sensorid.join(",")}) GROUP BY location, id`);

Why didn't it work?
After all, I take the select and id columns from table A and extract data from them that are equal to id == sensorid and place them in a new table
, what is the error and how to do it right?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Ruslan Ruslanov, 2019-06-10
@Riveran

1. do you have apostrophes (or what is it?) instead of quotation marks?
2. the handler does not see the variable, it sees a line like

SELECT location, id FROM A WHERE id IN (${list.sensorid.join(",")}) GROUP BY location, id

need like this:
await app.ds.pg.query('SELECT location, id FROM A WHERE id IN (' + ${list.sensorid.join(',')} + ') GROUP BY location, id');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question