0

I have this Mysql query that is working fine. However, I need to add 2 more conditions and I'm not sure how to do this.

//index.js

module.exports = {
    getHomePage: (req, res) => {

       let query ='SELECT Tbl_Email_mensagens.codigo AS Codigo, Tbl_Email_mensagens.mensagem AS Mensagem,Tbl_Email_mensagens.celular AS Celular, cm_custmaster.fullname AS NomeCompleto FROM Tbl_Email_mensagens LEFT JOIN cm_custmaster ON Tbl_Email_mensagens.celular = cm_custmaster.mobile';

        // execute query
        db.query(query, (err, result) => {
            if (err) {
                res.redirect('/');
            }
            res.render('index.ejs', {
                title: ""
                ,players: result
            });
        });
    },
};

I then need to add these 2 conditions:

Where group = '7' and send = '0'

Very thanks!

3
  • 1
    What tables these fields are from? Commented Feb 25, 2020 at 11:22
  • @Akina: Tbl_Email_mensagens Commented Feb 25, 2020 at 11:59
  • 1
    Does this answer your question? nodejs mysql multiple where query's Commented Feb 25, 2020 at 12:16

1 Answer 1

0
SELECT Tbl_Email_mensagens.codigo AS Codigo, 
       Tbl_Email_mensagens.mensagem AS Mensagem,
       Tbl_Email_mensagens.celular AS Celular, 
       cm_custmaster.fullname AS NomeCompleto 
FROM Tbl_Email_mensagens 
LEFT JOIN cm_custmaster ON Tbl_Email_mensagens.celular = cm_custmaster.mobile
WHERE Tbl_Email_mensagens.`group` = 7 
  AND Tbl_Email_mensagens.send = 0

Pay attention - the word group is reserved one, so it MUST be wrapped into backticks. But it is more safe to rename it, to some group_number, for example.

Whereas the quotes over the values are excess (you may store them if according field has any string datatype).

Sign up to request clarification or add additional context in comments.

3 Comments

Please, Now, i need to limit the number of characters displayed in the query 'Tbl_Email_mensagens.messagem AS Message' to just 40 characters. Thank you again
@MikailhP LEFT() function.
LEFT(Tbl_Email_mensagens.mensagem,40) AS Mensagem Thanks again

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.