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;
blog comments powered by Disqus |
|
|
|
|
|
|
|