View Full Version : using the NOT operator to exclude fields

02-27-2007, 07:18 AM
Hi all,

I want to be able to select all fields from a table except certain fields.

I came across the NOT operator in the MySQL ref. manual, and I wanted to check about the syntax of that operator.

Would this syntax work:
SELECT NOT id1, id2, id3, id4 FROM table

Or would this work:
SELECT NOT id1, NOT id2, NOT id3, NOT id4 FROM table

If neither, what is the shortest way that would work? Thanks!

02-27-2007, 03:11 PM
Neither will work. You have to specify the exact columns you want from your table. Some people use SELECT * to select all columns but that should only be used for testing purposes.

You can't use the NOT operator to specify which columns you do/do not want.

02-28-2007, 01:00 AM
OK, thanks. I can still do it, it will just be a bit more code then. Thank you!