MySQL
  Home arrow MySQL arrow Page 5 - Beginning MySQL Tutorial
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MYSQL

Beginning MySQL Tutorial
By: W.J. Gilmore
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 218
    1999-04-03

    Table of Contents:
  • Beginning MySQL Tutorial
  • Part 1: At First Glance
  • Part 2: Datatypes and Tables
  • Part 3: Manipulating the Database
  • Part 4: Advanced MySQL Commands

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Beginning MySQL Tutorial - Part 4: Advanced MySQL Commands


    (Page 5 of 5 )

    What we have covered so far is but a small part of what MySQL is capable of. Let's delve a little deeper into the language, exploring some of the more advanced commands of the language.

    Logical Operations

    MySQL includes full support of all basic logical operations.

    AND (&&)


    mysql> SELECT * FROM test WHERE mysql> (name = "Bugs Bunny") AND mysql> (phone_number = 5554321);

    Result:
    All records containing the name "Bugs Bunny" AND the phone number '5554321' will be displayed to the screen.

    OR ( || )


    mysql> SELECT * FROM test WHERE mysql> (name = "Bugs Bunny") OR mysql> (phone_number = 5554321);

    Result:
    All records containing the name "Bugs Bunny" OR the phone number '5554321' will be displayed to the screen.

    NOT ( ! )


    mysql> SELECT * FROM test WHERE mysql> (name != "Bugs Bunny");

    Result:
    All records NOT containing the name "Bugs Bunny" will be displayed to the screen.

    Order By


    mysql> SELECT * FROM test WHERE mysql> (name = "Bugs Bunny") ORDER BY mysql> phone_number;

    Result:
    All records containing the name "Bugs Bunny" will be displayed to the screen, ordered in respect to the phone_number.

    Search functions

    MySQL offers the user the ability to perform both general and specific searches on data.


    mysql> SELECT * FROM test WHERE mysql> (name LIKE "%gs Bunny");

    Result:
    All records containing the partial string "gs Bunny" will be displayed to the screen. This would include such names as: "Bugs Bunny", "ags Bunny", "gs Bunny", and "234rtgs Bunny".

    Notice that "LIKE" has been used instead of the equals sign (=). "LIKE" signifies that one is searching for an estimate of the data requested, and not necessarily an exact copy.

    The '%' sign could be placed anywhere within the string. The method in which the server searches for a string is dependent upon where one places the '%' sign.


    mysql> SELECT * FROM test WHERE mysql> (name LIKE "Bugs Bunny%");

    Result:
    All records containing the partial string "Bugs Bunny" will be displayed to the screen. This would include such names as: "Bugs Bunnys", "Bugs Bunnyyyy453", "Bugs Bunnytrtrtrtrtr", but not "gs Bunny".

    Focused Search Results

    One can also perform searches and display only certain columns.


    mysql> SELECT name FROM test WHERE mysql> (name = "Bugs Bunny");

    Result:
    name
    Bugs Bunny

    Alter table

    Another very important function of MySQL is the ability to modify previously created tables. This is accomplished via the ALTER statement. This function allows one to add, modify, and delete columns, as well as rename the table, among other functions.

    Example: Rename the table


    mysql> ALTER table test RENAME mytest;

    Example: Add a column


    mysql> ALTER table mytest ADD birthday DATE;

    Example: Modify a column


    mysql> ALTER table mytest CHANGE mysql> name newname VARCHAR (25);

    Example: Delete a column


    mysql> ALTER table mytest DROP newname;

    Executing the above four functions would modify test, creating the following table:


    mysql> TABLE mytest ( > email VARCHAR (25), > phone_number INT, > ID INT AUTO_INCREMENT, > birthday DATE );

    The topics covered within this article are but a short introduction of the capabilities of MySQL. However, these functions form the basis of almost all advanced commands to be found in the language. Above all, the most important lesson that one can remember is to practice, study the documentation, and become an active member of the mailing list archives (And obviously read DevShed frequently!). Only by taking an enthusiastic, even "aggressive" approach to the language can one successfully master it.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · A very simple and quick introduction to MYSQL, a useful reference for any...
       · Thanks for the help. I have been trying to find a cut and dried MySQL tutorial for...
       · its really helpful. it is very clear and easily understandable. thanks for this...
     

       

    MYSQL ARTICLES

    - MySQL Server Tuning Tips and Tricks
    - MySQL Query Optimizations and Schema Design
    - MySQL Benchmarking Tools and Utilities
    - MySQL Benchmarking Concepts and Strategies
    - Take Some Load off MySQL with MemCached
    - MySQL Table Prefix Changer Tool in PHP
    - Using the SIGNAL Statement for Error Handling
    - Error Handling Examples
    - Error Handling
    - Completing a Search Engine with MySQL and PH...
    - Paginating Result Sets for a Search Engine B...
    - Building a Search Engine with MySQL and PHP 5
    - Using Boolean Operators for Full Text and Bo...
    - PHP, MySQL and the PEAR Database
    - Working with PHP and MySQL





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
    Stay green...Green IT