O'Reilly logo

Beginning SQL by John W. Colby, Paul Wilton

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 5. Manipulating Data

In Chapter 3, you looked simply at getting raw data from the database using SQL queries. This chapter, however, examines how to use, alter, and manipulate data using SQL. It starts off with a look at math in SQL, though don't worry if math isn't your favorite subject, as SQL math is fairly basic! The chapter then turns to the manipulation of character data and takes you through a whole host of functions that cover everything from reversing the order of characters in a string to matching columns based on words that sound alike. After that, coverage dives into another look at NULL, in particular how it can alter results in unexpected ways and how to deal with those altered results. Finally, this chapter finishes with a look at copying data from one table to another using INSERT INTO and SELECT statements.

Understanding SQL Arithmetic

The available math functions in SQL are fairly limited, which reflects SQL's use as a tool for pulling out the raw data to answer questions. Any actual processing of the answers is really something left to high-level programming languages in middleware or front-end applications. For example, a Web server might connect to a database to pull back a customer's name and credit card details, but you wouldn't expect the database to process the card details.

You start by looking at the four basic math functions supported by all flavors of SQL, and then you look at some more sophisticated math functions, which, although not part of the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required