2

I try to execute this query:

SELECT ISBN FROM table2 WHERE 
NOT IN ISBN=('8426429807','840149768X')
group by ISBN 
ORDER BY AVG(`Book-Rating`) DESC LIMIT 10

but I get error this shape

1064 - 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 'IN ISBN=('8426429807','840149768X')

How can I use many isbn in Not In

Ahmed_Ali
  • 1,646
  • 2
  • 21
  • 39
Alper C
  • 25
  • 3

2 Answers2

4

Not In() syntax is:

expr NOT IN (value,...)

Basically, column/expression should come before Not In and you do not use = operator. It should be:

SELECT ISBN
FROM table2
WHERE ISBN NOT IN ('8426429807',
                   '840149768X')
GROUP BY ISBN
ORDER BY AVG(`Book-Rating`) DESC
LIMIT 10

Another way of writing same query is using NOT (expr IN (value, ...)):

SELECT ISBN
FROM table2
WHERE NOT (ISBN IN ('8426429807',
                    '840149768X'))
GROUP BY ISBN
ORDER BY AVG(`Book-Rating`) DESC
LIMIT 10
Madhur Bhaiya
  • 26,097
  • 10
  • 39
  • 51
0

You should use where column_name NOT IN ( col_value1, col_value2)

select ISBN from table2
where ISBN NOT IN ('8426429807','840149768X')
group by ISBN 
ORDER BY AVG(`Book-Rating`) DESC LIMIT 10
scaisEdge
  • 124,973
  • 10
  • 73
  • 87