1

I tried to use the select sql option in node js sql plugins. But I get a error with this syntax :

con.query( 'SELECT token FROM utilisateursinvitation WHERE nomwork = ?  AND 
Rejoint = ?  EXCEPT   SELECT token FROM utilisateursinvitation WHERE nomwork 
= ?  AND Rejoint = ? AND nomdugroupe = ?  ', 
[nomwork,tatazueyzyu,"nomdugroupe"], function (error, results, fields) {

and the error :

Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'EXCEPT SELECT token FROM utilisateursinvitation WHERE nomwork = 'nomdugroupe' ' at line 1

Because I don't know the correct syntax. Can you help me ? THanks!

mataka
  • 115
  • 1
  • 10
  • 3
    Possible duplicate of [Error when using except in a query](https://stackoverflow.com/questions/16092353/error-when-using-except-in-a-query) – CannedMoose Apr 17 '18 at 10:21

1 Answers1

1

EXCEPT is not MySQL syntax.

Instead, you can use NOT IN or NOT EXISTS:

SELECT ui.token
FROM ui.utilisateursinvitation ui
WHERE ui.nomwork = ?  AND ui.Rejoint = ?  AND
      NOT EXISTS (SELECT 
                  FROM utilisateursinvitation ui2
                  WHERE ui2.token = ui.token AND
                        ui2.nomwork = ?  AND ui2.Rejoint = ? AND
                        nomdugroupe = ?  
                 );

Or, if you are trying to fine tokens that have nomwork and Rejoint as the input values, but not a particular nomdugroupe:

SELECT ui.token
FROM ui.utilisateursinvitation ui
WHERE ui.nomwork = ?  AND ui.Rejoint = ?  
GROUP BY ui.token
HAVING SUM(nomdugroupe = ?) > 0;
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786