2
Taking into account the need to bring the result of a second table, based on the result of the first, how would you do this with Nodejs ?
In PHP I would bring the result, and inside a while
did another query by passing the ID of the first query (I know that is not the best practice).
//List users
router.get("/users", (req, res) => {
let query = "SELECT * FROM ??";
let table = ["users"];
query = mysql.format(query, table);
connection.query(query, (err, rows) => {
if(err){
res.json({"Error": true, "Message": "Erro ao executar query do Mysql"});
}else{
res.json({"Error": false, "Message": "Successo", "Users": rows});
}
});
});
List information from the user
let query = "SELECT * FROM ?? WHERE ?? = ?";
let table = ["users_info"];
query = mysql.format(query, table);
It would be in the case of these two, list the user and list his information in another table.
You can show the two SELECT you want to do?
– Sergio
@Sergio Editei o post
– Rafael Augusto
Ok, and the query is only for 1 user at a time right?
– Sergio
What is the column of
users
which is reference tousers_info
and what’s the column? You can do it with aLEFT JOIN
.– Sergio
@Sergio Yes, one user at a time, the columns would be
sexo
,nascimento
,descricao
, in this table, I have a column that has theid_user
– Rafael Augusto