Home > Net >  Requête JPQL JEE
Requête JPQL JEE

Time:03-09

Please i need to select list of employees except the employees who have the role admin. However I got a syntax issue. this is the code : SELECT e FROM Employee e EXCEPT SELECT e FROM Employee e WHERE e.role = 'admin';

CodePudding user response:

The best way to select all records from a table except those which satisfy a condition is using a WHERE clause with a negative comparison (any of !=, <> or NOT).

You may find more information about SQL's WHERE clauses there: https://www.w3schools.com/sql/sql_where.asp

In your specific case, something like this should do the trick:

SELECT *
FROM Employee
WHERE role != 'admin';

CodePudding user response:

You don't appear to be selecting any fields.

Here's an example of using except

SELECT id, name, category, price FROM Books1 Except SELECT id, name, category, price FROM Books1 WHERE price > 5000

  • Related