Alper C
Alper C

Reputation: 25

MSQL How can I use a many statement in NOT IN

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

Upvotes: 2

Views: 63

Answers (2)

ScaisEdge
ScaisEdge

Reputation: 133370

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

Upvotes: 0

Madhur Bhaiya
Madhur Bhaiya

Reputation: 28834

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

Upvotes: 4

Related Questions