Buy Used
Used - Very Good See details
Price: £6.47

or
Sign in to turn on 1-Click ordering.
 
   
Have one to sell? Sell yours here
MySQL Cookbook
 
 
Tell the Publisher!
I’d like to read this book on Kindle

Don't have a Kindle? Get your Kindle here, or download a FREE Kindle Reading App.

MySQL Cookbook [Paperback]

Paul DuBois
4.8 out of 5 stars  See all reviews (4 customer reviews)

Available from these sellers.


‹  Return to Product Overview

Product Description

Brad Crockett, Big Blue and Cousins, Feb 2003

MySQL Cookbook' is a great book for anyone developing a user interface to a MySQL database.

Review

"...MySQL Cookbook tells you exactly how to solve literally hundreds of problems that you are likely to encounter in getting a MySQL database solution up and running." - Computer Trade Shopper, November 2003

Book Description

Solutions & Examples for Database Developers and DBAs --This text refers to an alternate Paperback edition.

Product Description

While MySQL has turned up among high profile users such as Yahoo!, NASA and the U.S. Census Bureau, the rising popularity of this open source database is especially keen among users with little database experience. These days, even a small organization or web site has uses for a database, and MySQL is an obvious choice. Affordable and easy to use, MySQL packs the power, speed and efficiency that enable it to rival expensive, proprietary database solutions. Yet, even if you know the basics, anyone without practical MySQL experience--novices and skilled DBAs alike--might stumble over common database-related tasks. Fortunately, there's a sensible shortcut.

MySQL Cookbook provides a unique problem-and-solution format that offers practical examples for everyday programming dilemmas. For every problem addressed in the book, there's a worked-out solution or "recipe"--short, focused pieces of code that you can insert directly into your applications. But MySQL Cookbook is more than a collection of cut-and-paste code. You also get explanations of how and why the code works, so you can learn to adapt the techniques to similar situations.

The book covers a lot of ground. Solutions for typical MySQL dilemmas range from simple ways to find all records that contain a given string, to more difficult problems, such as finding matching/non-matching records in two tables. Whether you use MySQL on Unix, Linux, Windows or the Mac OS X platform, the book will show you how to:

  • Import data from external sources
  • Export data for use by external programs
  • Access MySQL from your web server
  • Use scripts with MySQL to read queries from a file
  • Access MySQL from within client programs that use Perl, PHP, Java, Python and other languages
  • Construct queries that solve commonly-occurring questions
  • Interact with the server
This learn-as-you-go resource will help users of all levels exploit MySQL more fully. MySQL Cookbook supplies you with an armory of ready-made techniques for specific problems so that, even if you're an experienced MySQL user, you don't have to write everything from scratch.

From the Publisher

MySQL Cookbook provides a unique problem-and-solution format that offers practical examples for everyday programming dilemmas. For every problem addressed in the book, there's a worked-out solution or "recipe"--short, focused pieces of code that you can insert directly into your applications. More than a collection of cut-and-paste code, this book explanation how and why the code works, so you can learn to adapt the techniques to similar situations.

About the Author

is one of the primary contributors to the MySQL Reference Manual, a renowned online manual that has supported MySQL administrators and database developers for years, now available in an attractive paper format from the O'Reilly Community Press. He is also the author of Using csh & tcsh and Software Portability with imake by O'Reilly, as well as MySQL and MySQL and Perl for the Web by New Riders.

Excerpted from My SQL Cookbook by Paul DuBois. Copyright © 2002. Reprinted by permission. All rights reserved.

CHAPTER 3 - Record Selection Techniques

3.0 Introduction
This chapter focuses on the SELECT statement that is used for retrieving information from a database.It provides some essential background that shows various ways you can use SELECT to tell MySQL what you want to see.You should find the chapter helpful if your SQL background is limited or if you want to find out about the MySQL-specific extensions to SELECT syntax.However, there are so many ways to write SELECT queries that we’ll necessarily touch on just a few.You may wish to consult the MySQL Reference Manual or a MySQL text for more information about the syntax of SELECT, as well as the functions and operators that you can use for extracting and manipulating data.

SELECT gives you control over several aspects of record retrieval:
•Which table to use
•Which columns to display from the table
•What names to give the columns
•Which rows to retrieve from the table
•How to sort the rows

Many useful queries are quite simple and don’t specify all those things.For example, some forms of SELECT don’t even name a table —a fact used in Recipe 1.31, which discusses how to use mysql as a calculator. Other non –table-based queries are useful for purposes such as checking what version of the server you’re running or the name of the current database:

However, to answer more involved questions, normally you’ll need to pull information from one or more tables.Many of the examples in this chapter use a table named mail, which contains columns used to maintain a log of mail message traffic between users on a set of hosts.Its definition looks like this:

CREATE TABLE mail
(
t DATETIME, #when message was sent
srcuser CHAR(8), #sender (source user and host)
srchost CHAR(20),
dstuser CHAR(8), #recipient (destination user and host)
dsthost CHAR(20),
size BIGINT, #message size in bytes
INDEX (t)
);

To create the mail table and load its contents, change location into the tables directory of the recipes distribution and run this command:

%mysql cookbook This chapter also uses other tables from time to time.Some of these were used in previous chapters, while others are new.For any that you need to create, do so the same way as for the mail table, using scripts in the tables directory.In addition, the text for many of the scripts and programs used in the chapter may be found in the select directory.You can use the files there to try out the examples more easily.

Many of the queries shown here can be tried out with mysql, which you can read about in Chapter 1. Some of the examples issue queries from within the context of a programming language. See Chapter 2 for background on programming techniques.

3.1 Specifying Which Columns to Display

Problem
You want to display some or all of the columns from a table.
Solution
Use *as a shortcut that selects all columns.Or name the columns you want to see explicitly.
Discussion
To indicate what kind of information you want to see from a table, name a column or a list of columns and the table to use.The easiest way to select output columns is to use the *specifier, which is a shortcut for naming all the columns in a table:

It’s certainly easier to use *than to write out a list of column names. However, with*, there is no guarantee about the order in which columns will be returned.(The server returns them in the order they are listed in the table definition, but this may change if you change the definition.See Chapter 8.)Thus, one advantage of naming the columns explicitly is that you can place them in whatever order you want.Suppose you want hostnames to appear before usernames, rather than after.

‹  Return to Product Overview