var mysql = require('mysql');
var con = mysql.createConnection({
host: "localhost",
user: "myusername",
password: "mypassword",
database: "mydb"
});
con.connect(function(err) {
if (err) throw err;
var sql = "SELECT users.name AS user, products.name AS favorite FROM users RIGHT JOIN products ON users.favorite_product = products.id";
con.query(sql, function (err, result) {
if (err) throw err;
console.log(result);
});
});
[
{ user: 'John', favorite:
'Chocolate Heaven' },
{ user: 'Peter', favorite: 'Chocolate Heaven' },
{
user: 'Amy', favorite: 'Tasty Lemons' },
{
user: null, favorite: 'Vanilla Dreams' }
]