therealshankman
therealshankman

Reputation: 97

Select specific element from set of MYSQL elements in node js

I have a Request table that has some columns. I need to select a row in the table and then use a specific column value(say request_initiator) to search it in another table.

connection.query('SELECT * FROM Requests WHERE `request_id` = ?', req.body.id, function(error,results, fields){}

My results gives me multiple objects which then contains the component elements with different value.

0   
request_id  1
user_id "user1"
from    "[email protected]"
to  "owner2"
status  "deleted"
1   
request_id  2
user_id "user4"
from    "[email protected]"
to  "owner2"
status  "pending"    

I have to access results to get from and then search it in Owners table.

However, results.from doesn't give anything. results[0] gives the first object but I can't access the elements of that list

How should I proceed with this?

Upvotes: 2

Views: 574

Answers (1)

TheMaster
TheMaster

Reputation: 50452

results is a array of multiple objects. You can access the from key's value using

results[0]["from"]

Upvotes: 2

Related Questions