Home > Articles

Expressions, Conditions, and Operators

  • Print
  • + Share This
This chapter is from the book

On Day 2, "Introducing the Query," you used SELECT and FROM to manipulate data in interesting (and useful) ways. Today you learn more about SELECT and FROM. You will expand the basic query with some new terms, a new clause, and a group of handy items called operators. When the sun sets on Day 3, you will

  • Know what an expression is and how to use it

  • Know what a condition is and how to use it

  • Be familiar with the basic uses of the WHERE clause

  • Be able to use arithmetic, comparison, character, logical, and set operators

  • Have a working knowledge of some miscellaneous operators

NOTE

We used Oracle's Personal Oracle and MySQL to generate today's examples. Other implementations of SQL may differ slightly in the way in which commands are entered or output is displayed, but the results are basically the same for all implementations that conform to the ANSI standard.

Working with Query Expressions

The definition of an expression is simple: An expression returns a value. Expression types are very broad, covering different data types such as String, Numeric, and Boolean. In fact, pretty much anything following a clause (SELECT or FROM, for example) is an expression. In the following example, AMOUNT is an expression that returns the value contained in the AMOUNT column:

SELECT amount FROM checks;

In the following statement NAME, ADDRESS, PHONE, and ADDRESSBOOK are expressions:

SELECT NAME, ADDRESS, PHONE
FROM ADDRESSBOOK;

Now, examine the following WHERE clause:

WHERE NAME = 'BROWN'

It contains a condition, NAME = 'BROWN', which is an example of a Boolean expression. NAME = 'BROWN' will be either TRUE or FALSE, depending on the condition =.

  • + Share This
  • 🔖 Save To Your Account