E
E
ettaluni2021-06-14 23:47:49
SQLite
ettaluni, 2021-06-14 23:47:49

How to compare data from two tables?

Good evening. In my development I use nodejs and sqlite database. Now that there is a lot of data, I realized that it was ridiculous to implement the selection and comparison of data from tables. Here's a code example:

let table1res = await db.select('select * from table1');
for (let i = 0; i < table1res.length; i++) {
  arRes.push({
    option1: param,
    option2: resto,
  });
table2res = await db.select('select * from table2 where ID="tableres.ID"');
for (let j = 0; j < table2res; j++)
  /* и пошел второй перебор и сопоставление */
}

All this is done for a very long time, I assume that it is not advisable to do a bunch of small lookup queries with where.
How can this business be optimized? How can you immediately get a two-dimensional complex array of a one-to-many relationship? Maybe there is some tricky SQL or js ways to compare (ready-made functions)?
60c7c0b53e9ae024735763.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
xirurgx3d, 2021-06-19
@xirurgx3d

use

LEFT JOIN

example from documentation
FROM table1
LEFT JOIN table2
ON table1.column_name = table2.column_name;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question