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

    You will be asked to write SQL scripts to display required information, like we did in the homework.…

    • 512 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    Cis 515week 3

    • 1024 Words
    • 4 Pages

    Bibliography: (2012). Database systems: Design, implementation, and management. (10 ed.). United States of America: Joe Sabatino.…

    • 1024 Words
    • 4 Pages
    Good 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

    SQL is the programming language used to manipulate data and data objects in a relational database management system. TRUE…

    • 287 Words
    • 1 Page
    Satisfactory Essays
  • Satisfactory Essays

    unit 6

    • 360 Words
    • 2 Pages

    1) SQL is the programming language used to manipulate data and data objects in a relational database management system.…

    • 360 Words
    • 2 Pages
    Satisfactory 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
  • 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
  • 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
  • Satisfactory Essays

    Relational Database Paper

    • 547 Words
    • 3 Pages

    The purpose of a query is to retrieve information from a table or tables, which can be based on some type of criteria. To put it simply, a query is designed to get you an answer from data already stored in the database.…

    • 547 Words
    • 3 Pages
    Satisfactory 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