In my database I have two tables. Let's call them A and B. B table has foreign keys related to ids of records in A table.
I fetch couple of ids from A table and I want to find records in B table with foreign keys matching to those ids. However not every record in A table has records related to it in B table.
So in my code it looks like this:
var idsFromA = [1, 2, 3, 4, 5]
connection.query("SELECT * FROM B_table WHERE a_id = ?", idsFromA, function(err, results) {
if (err) {
return console.log(err)
} else {
// always empty
console.log(results);
}
});
Let's say ids number 1 and 2 from table A has record related to them in table B. Rest of them not. I want to get records from table B with those foreign keys but I receive only an empty array. It works only if I type query with only one matching value. But for the whole array of values where some of them don't have related record not.
How can I fix it and get information about those record?