Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL logical operator

What are the occupations that are NOT student, lawyer or educator? List them in descending alphabetical order?

SELECT Occupation 
  FROM Viewer 
 WHERE occupation NOT IN 'student,lawyer,educator' 
ORDER BY occupation desc; 

I keep getting an error. What am i doing wrong?

like image 902
ckp25 Avatar asked Jun 26 '26 07:06

ckp25


1 Answers

IN requires a list of expressions surrounded by parentheses:

SELECT Occupation
FROM Viewer
WHERE occupation NOT IN ('student','lawyer','educator')
ORDER BY occupation desc;

See the documentation for IN to see the correct syntax:

IN condition

like image 130
Mark Byers Avatar answered Jun 29 '26 00:06

Mark Byers



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!