3 Tutorial Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144

       3.1 Connecting to and Disconnecting from the Server . . . . . . . . . . . . . . . . . . . . . . . .144

       3.2 Entering Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145

       3.3 Creating and Using a Database. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
              3.3.1 Creating and Selecting a Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
              3.3.2 Creating a Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
              3.3.3 Loading Data into a Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .151
              3.3.4 Retrieving Information from a Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
              3.3.4.1 Selecting All Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
              3.3.4.2 Selecting Particular Rows. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
              3.3.4.3 Selecting Particular Columns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .154
              3.3.4.4 Sorting Rows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
              3.3.4.5 Date Calculations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .157
              3.3.4.6 Working with NULL Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .160
              3.3.4.7 Pattern Matching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
              3.3.4.8 Counting Rows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
              3.3.4.9 Using More Than one Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165

       3.4 Getting Information About Databases and Tables . . . . . . . . . . . . . . . . . . . . . . . . 167

       3.5 Examples of Common Queries. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .168
              3.5.1 The Maximum Value for a Column . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
              3.5.2 The Row Holding the Maximum of a Certain Column . . . . . . . . . . . . . . .169
              3.5.3 Maximum of Column per Group . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .169
              3.5.4 The Rows Holding the Group-wise Maximum of a Certain Field . . . . . 170
              3.5.5 Using user variables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .171
              3.5.6 Using Foreign Keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
              3.5.7 Searching on Two Keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .172
              3.5.8 Calculating Visits Per Day . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .173
              3.5.9 Using AUTO_INCREMENT. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173

       3.6 Using mysql in Batch Mode. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175

       3.7 Queries from Twin Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .176
              3.7.1 Find all Non-distributed Twins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .176
              3.7.2 Show a Table on Twin Pair Status . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179

       3.8 Using MySQL with Apache . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .179

 

| | | | | | | |
  • Return to Table of Contents
  •  

    Customer Support CentreMySQL Reference Manual

    Web Hosting Services
    UNIX WEB HOSTING
    MERCHANT ACCOUNTS
    DEDICATED SERVERS
    E-COMMERCE HOSTING
    SUPPORT & FAQ's
    TERMS OF USE
    Domain Services
    DOMAIN
    REGISTRATION
    MANAGE
    YOUR ACCOUNT
    SUPPORT & FAQ's
    TERMS OF USE
    Corporate Info
    ABOUT US
    OUR NETWORK
    CONTACT US
    SITE MAP
    Copyright © 2002 Dyntex Group, Inc. All Rights Reserved
  • Return to Table of Contents
  • Back to top