Home arrow BrainDump arrow Page 2 - More Advanced SQL Statements

UNION STATEMENT - BrainDump

In this third part to a series on beginning SQL, you'll learn how to use SQL statements to manipulate entire tables: to join them, alter them, and even delete them. It's all part of keeping a firm grip on your databases. Keep reading to learn more.

TABLE OF CONTENTS:
  1. More Advanced SQL Statements
  2. UNION STATEMENT
  3. And along came baby
  4. Speeding Up the Search
  5. OOPS I DID IT AGAIN
By: James Payne
Rating: starstarstarstarstar / 23
October 08, 2007

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

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
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

BRAINDUMP ARTICLES

- Apple Founder Steve Jobs Dies
- Steve Jobs` Era at Apple Ends
- Google's Chrome Developer Tool Updated
- Google's Chrome 6 Browser Brings Speed to th...
- New Open Source Update Fedora 13 is Released...
- Install Linux with Knoppix
- iPad Developers Flock To SDK 3.2
- Managing a Linux Wireless Access Point
- Maintaining a Linux Wireless Access Point
- Securing a Linux Wireless Access Point
- Configuring a Linux Wireless Access Point
- Building a Linux Wireless Access Point
- Migrating Oracle to PostgreSQL with Enterpri...
- Demystifying SELinux on Kernel 2.6
- Yahoo and Microsoft Create Ad Partnership

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: