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: '巧克力天堂' },
{ user: 'Peter', favorite: '巧克力天堂' },
{ user: 'Amy', favorite: '美味柠檬' },
{ user: null, favorite: '香草梦' }
]