BrainDump
  Home arrow BrainDump arrow Page 2 - More Advanced SQL Statements
Dev Shed Forums 
Administration  
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 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
IBM Rational Software Development Conference
 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? 
BRAINDUMP

More Advanced SQL Statements
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 7
    2007-10-08

    Table of Contents:
  • More Advanced SQL Statements
  • UNION STATEMENT
  • And along came baby
  • Speeding Up the Search
  • OOPS I DID IT AGAIN

  • 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

    TestComplete™ automates software testing for a fraction of what the big guys charge. Easy functional and load testing for all Windows, .NET, Java and Web apps. Download a free trial now.

    More Advanced SQL Statements - UNION STATEMENT
    (Page 2 of 5 )

    The UNION Statement is similar to the JOIN statement, with the exception that with the UNION statement, the data types must be the same and it will only display unique values.


    SELECT SocialSecurity FROM EMPLOYEES

    UNION

    SELECT SocialSecurity FROM BIRTHDAYS;

    This would give us a list of social security numbers in each table. Since all are the same in this example, it would be pointless to do this. However, if you had a list of employees from two companies with social security numbers, you could wed the two together to create an entire list of social security numbers.

    If we wanted to see a list of all social security numbers, even though they would be duplicates, we would use the UNION ALL statement.

     

    SELECT SocialSecurity FROM EMPLOYEES

    UNION ALL

    SELECT SocialSecurity FROM BIRTHDAYS;

    Altering Tables

    Now that you have made your table, you suddenly decide you want to add some columns and maybe even drop some columns. The ALTER statement allows us to do exactly that.

    Let's say we want to add a column called IQ to our table (they've decided to give people salaries based on their intelligence quotient). We'll need to know the data-type of the column first, in this case, integer.


    ALTER TABLE EMPLOYEE ADD IQ Integer(30);

    This will add the IQ column to the table.

    Now after the president sees the great dip in his salary because of his low IQ, he may ask you (the new the top earner in the company) to delete that column you just made.

    Not a problem. Well. Aside from the impending dip in your salary.


    ALTER TABLE EMPLOYEE DROP COLUMN IQ;

    More BrainDump Articles
    More By James Payne


       · This is the third installment in my Beginner SQL series. It covers things like the...
     

       

    BRAINDUMP ARTICLES

    - Outsourcing: the Hoopla, the Reality
    - MySQL Plays in the Sun
    - All About SQL Functions
    - SQL: Functioning in the Real World
    - More Advanced SQL Statements
    - Beginning SQL the SEQUEL: Working with Advan...
    - Beginning SQL
    - A Look at the VI Editor
    - A Quick Tour of Boo
    - Book Review: Open Source Licensing
    - PGP and GPG: Email for the Practical Parano...
    - Microsoft Continues War on Open Source
    - Secure Remote Desktop Sharing with VNC on Li...
    - A Look at Google Project Hosting
    - What we can Learn from Two Linux vs. Microso...

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway