Previous Topic: Exercise 4-3Next Topic: Using Keywords in Predicates


Exercise 4-4

Try It Using NOT

Use NOT following the word WHERE to select rows that do not meet the search condition.

Employees who do not live in Boston are not affected by the new tax. Create another SELECT statement to retrieve all employees who do not live in Boston. Use the keyword NOT after WHERE. Display employee ID, first and last name, and city.

The result looks like this:

 EMP_ID  EMP_FNAME             EMP_LNAME             CITY  ------  ---------             ---------             ----    2299  Samuel                Spade                 Canton    4773  Janice                Dexter                Medford    3338  Mark                  White                 Canton    2246  Marylou               Hamel                 Medford    1034  James                 Gallway               Stoneham    2424  Ronald                Wilder                Natick    3767  Frank                 Lowe                  Natick    2898  Mary                  Umidy                 Medford    3449  Cynthia               Taylor                Concord    3082  John                  Brooks                Camden    3341  Carl                  Smith                 Newton    3199  Martin                Loren                 Grover    4660  Bruce                 MacGregor             Camden    2209  Michael               Smith                 Brookline    2894  William               Griffin               Taunton    4001  Jason                 Thompson              Natick    5090  Stephen               Wills                 Canton    1765  David                 Alexander             Grover    4456  Thomas                Thompson              Newton    2145  Martin                Catlin                Wilmington    3991  Fred                  Wilkins               Taunton    3778  Jane                  Ferndale              Medford    4358  Judith                Robinson              Wilmington    2180  Joan                  Albertini             Medford    2106  Susan                 Widman                Medford    3222  Louise                Voltmer               Brookline    4002  Linda                 Roy                   Wilmington    2096  Thomas                Carlson               Brookline    2004  Eleanor               Johnson               Medford    5103  Adele                 Ferguson              Brookline    5008  Timothy               Fordman               Brookline    4321  George                Bradley               Grover    2598  Mary                  Jacobs                Camden    3764  Deborah               Park                  Brookline    2461  Alice                 Anderson              Medford    2448  David                 Lynn                  Natick    1234  Thomas                Mills                 Brookline    2466  Patricia              Bennett               Medford    4027  Cecile                Courtney              Natick    2174  Jonathan              Zander                Brookline    2781  Joseph                Thurston              Stoneham    3704  Richard               Moore                 Dedham    4008  Robert                Clark                 Brookline    3433  Herbert               Crane                 Newton    3288  Ralph                 Sampson               Newton    4703  Martin                Halloran              Brookline    3294  Carolyn               Johnson               Brookline    3118  Alan                  Wooding               Canton    3769  Julie                 Donelson              Grover  49 rows processed

If your results do not match what you see above, check Review Answers for Chapter 4 for the correct SQL syntax. Remember that result tables may be shortened in this guide.

What is another way of getting this information?

You could have used <> (not equal) instead of the keyword NOT.