Preview

Sql Essay

Good Essays
Open Document
Open Document
641 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Sql Essay
SQL has many unique commands that help simplify database commands. SQL’s UNION command allows us to combine the results of two or more database queries that are not necessarily linked through a database relationship. For example, if we have a school database and wish to use it to create a master contact list for all students, faculty and staff that could be difficult. Looking at our database, we can discover that the records corresponding to each of these constituencies appears in separate database tables. Our first impulse might be to export the data from each table into a spreadsheet and combine the information there. However, an easier way would be to combine these records within the database by writing separate queries for each constituency and combining the results of those queries with the UNION statement.
The syntax of the UNION statement is the following:
SELECT_Query_1
UNION [ALL]
SELECT_Query_2

The purpose of the SQL UNION command is to combine the results of two queries together. UNION is somewhat similar to the JOIN command in that they are both used to related information from multiple tables. This command does have some restrictions. One restriction of UNION is that all corresponding columns need to be of the same data type. Also, when using UNION, only distinct values are selected similar to SELECT DISTINCT. Also, each SELECT statement within the UNION must have the same number of columns. The columns must also have similar data types and all of the columns in each SELECT statement must be in the same order. There is also a UNION ALL command (Rob and Coronel (2009). The purpose of the SQL UNION ALL command is also to combine the results of two queries together. The difference between UNION ALL and UNION is that, while UNION only selects distinct values, UNION ALL selects all values.
The syntax is as follows:
[SQL Statement 1]
UNION [ALL]
[SQL Statement 2] (SQL Book)

Another helpful SQL command is INTERSECT. Similar to the UNION



References: Rob, P., & Coronel, C. (2009). Database Systems Design, Implementation, and Management (8th ed.). Boston, MA: Thomson Course Technology. SQL Book. Retrieved from http://www.sqlbook.com/SQL/SQL-UNION-and-UNION-ALL-32.aspx BLACK WASP. Retrieved from http://www.blackwasp.co.uk/SQLExceptIntersect.aspx

You May Also Find These Documents Helpful

  • Good Essays

    Coronel, C., Morris, S., & Rob, P. (2013). Database systems: Design, implementation, and management (10th ed.). Boston, MA: Course Technology.…

    • 699 Words
    • 3 Pages
    Good Essays
  • Good Essays

    The SELECT statement is the primary means of extracting data from database tables, and allows you to determine exactly which data you want to extract by means of different comparison operators used in the WHERE clause. This includes the use of specific "wild card" characters which allow you to search for character or number patterns within the data. You can also perform mathematical expressions within the SELECT statement to create derived output. The ORDER BY clause allows you to sort the output data in either ascending (the default) or descending order. Lab #5 will explore all of these applications of the SELECT statement.…

    • 1559 Words
    • 7 Pages
    Good Essays
  • Satisfactory Essays

    Sci/275 Quiz

    • 487 Words
    • 2 Pages

    6. Was there anything lost when table A was summarized into table B? Briefly explain its…

    • 487 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    cis3730_Exam1_Studyguide

    • 512 Words
    • 2 Pages

    Understand the three components of a basic select statement and what do they mean (select, from, where).…

    • 512 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Kroenke, D. M., & Auer, D. J. (2010). Database Concepts (4th ed.). Retrieved from https://ecampus.phoenix.edu/content/eBookLibrary2.…

    • 553 Words
    • 3 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Unit 6 True

    • 287 Words
    • 1 Page

    The * in SELECT * clause of an SQL statement is a wildcard for returning all columns in a table. TRUE…

    • 287 Words
    • 1 Page
    Satisfactory Essays
  • Satisfactory Essays

    unit 6

    • 360 Words
    • 2 Pages

    6) The * in SELECT * clause of an SQL statement is a wildcard for returning all columns in a table.…

    • 360 Words
    • 2 Pages
    Satisfactory Essays
  • Better Essays

    Dbm 381 Week 1 Individual

    • 971 Words
    • 4 Pages

    Pratt, P.J., & Adamski, J.J. (2012). Concepts of database management (7th ed.). Retrieved from The University of Phoenix eBook Collection database.…

    • 971 Words
    • 4 Pages
    Better Essays
  • Good Essays

    07

    • 4772 Words
    • 25 Pages

    1) The SQL CREATE TABLE statement is used to name a new table and describe the table's columns.…

    • 4772 Words
    • 25 Pages
    Good Essays
  • Powerful Essays

    Assignment Homework

    • 1073 Words
    • 5 Pages

    2. Write queries that performs a join, a subquery, a correlated subquery using the student, enrollment, grade, and zipcode tables. Execute each query to show that it produces the same results. (15 pts)…

    • 1073 Words
    • 5 Pages
    Powerful Essays
  • Good Essays

    References: Coronel, C., Morris, S., & Rob, P. (2013). Database systems: Design, implementation, and management (10th ed.). Independence, KY: Cengage.…

    • 906 Words
    • 3 Pages
    Good Essays
  • Good Essays

    "SQL Sql Database Language Data Standard Query Programming Set." Business, Economy, Market Research, Finance, Income Tax Informations. N.p., n.d. Web. 26 Sept. 2012. <http://www.economicexpert.com/a/SQL:programming:language.htm>.…

    • 701 Words
    • 3 Pages
    Good Essays
  • Good Essays

    Jrotc Essay

    • 489 Words
    • 2 Pages

    Before you can make someone else proud, you must first make yourself proud. Somewhere along everybody’s life, one gains a sense of leadership and moral standards. JROTC specializes in fine tuning and maintaining these characteristics. There is much to learn about when you join the JROTC program. With the skills and knowledge that JROTC provides, you will find yourself succeeding in most that you do and will go a long way in a short amount of time.…

    • 489 Words
    • 2 Pages
    Good Essays
  • Good Essays

    After the Civil war, President Lincoln reconstruction plans for the United States was to unify and reconcile the north and the south. Republican dislike President Lincoln reconstruction plan due to their belief that the south should be punished. Due to assassination of President Lincoln, President Andrew Johnson’s carried on with the reconstruction for the south. President Johnson plans range from disallowing freed slave’s freedom, returning land and property back to southerners, and establishing white based governments in the south. All though President Johnson had a grand plan in restoring the north and south states, Republican of congress had their own image of reconstruction.…

    • 461 Words
    • 2 Pages
    Good Essays
  • Good Essays

    Leswnick, H. (1992). Being a lawyer: Indivitual choice and responsibility in the practice of law. West Publishing Company.…

    • 851 Words
    • 4 Pages
    Good Essays

Related Topics