MySQL has a wide variety of built-in operators and functions that can be useful for writing queries. Most of these are for use in the SELECT and WHERE clauses. There are also some special grouping functions for use in the GROUP BY clause. We have already used the basic comparison operators and the count() and max() functions. A vast number of functions are available. In this chapter, we take a tour of the most useful ones. This book is not trying to be a function reference by any means ”we are just trying to give you a feel for the types of functionality available. We will cover the following:
One important point to note is that, in MySQL, any expression containing NULL will evaluate to NULL , with a few exceptions we will note as we go along. We will discuss this further in the section on comparison operators. In this chapter, we will make some use of the SELECT statement without any tables. We can use SELECT as a basic calculator. For example, if we type select 2+2; we will get the result +-----+ 2+2 +-----+ 4 +-----+ 1 row in set (0.42 sec) We can execute any expression without tables and have access to a full range of math and other operators and functions. Although the capability to execute 2+2 is trivial, the capability to do math at the SELECT level is not always so. For example, this lets you perform financial analysis of values in tables and display the results in a report. In all MySQL expressions, you can use parentheses to control the order in which subexpressions are evaluated, as you would in any programming language. We will begin by looking at the operators. |