hello ,
i wanna do something as below but the problem that names and address out of the connection query are empty how can i assign them and the send them to the page?

app.get('/reports', (req, res)=>{

    let sql = "SELECT DISTINCT name from users_table  ;";
    let names;
    let query = connection.query(sql,(err,results) => {
    if(err) throw err;

let sql2 = "SELECT DISTINCT address from users_table  ;";
    let addresss ;
    let query2 = connection.query(sql2,(err,results) => {
    if(err) throw err;

    title:'Reports ',



i wanna get the result of sql 1 and save it in names and the result of sql 2 and save it in address and then in render send the results in reports page but the problem out of sql 1 connection if i consoled the name i find it empty however in the connection there is result

so why it is empty out of the connection ??

Ahh, now I see it. Your post title asked about the connection result which as an old MySQL person I took as exactly that.
Nod to https://www.connectionstrings.com/mysql/

If I swap your use of connection for "query" then that changes the question to something else.

While I can't guess your end goal of the query I would change the query to a single query since both appear to be from the same table.

commented: assume that the two queries are from different tables what should i do now? +0

THanks for helping with this. I also have the same situation!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.