DB2 Questions   «Prev  Next»

Essential SQL, Select Statement Questions

  1. Question:Describe the evolution of the "Structured Query Language".

    Answer: The Structured Query Language (SQL) has undergone significant evolution since its inception in the 1970s. Here's a brief overview of its development: Early beginnings (1970s)
    • SQL was first developed at IBM by Donald Chamberlin and Raymond Boyce as a language for managing and manipulating data in relational databases.
    • Initially called SEQUEL (Structured English Query Language), it was later renamed to SQL due to trademark issues.

    SQL/DS and System R (1970s-1980s)
    • SQL/DS, a database management system developed by IBM, was the first commercial product to use SQL.
    • System R, a research project at IBM, further developed and refined SQL.

    SQL Standardization (1980s)
    • In 1986, the American National Standards Institute (ANSI) published the first SQL standard, SQL-86.
    • The International Organization for Standardization (ISO) adopted SQL-86 as an international standard in 1987.
    SQL-89 and SQL-92 (1989-1992)
    • SQL-89 added new features, such as outer joins and recursive queries.
    • SQL-92, also known as SQL2, introduced significant improvements, including:

    Subqueries
    • Common table expressions (CTEs)
    • Window functions
    • triggers

    SQL:1999 and SQL:2003 (1999-2003)
    • SQL:1999 added features like full-text search and recursive queries.
    • SQL:2003 introduced:
    • XML support
    • Regular expressions
    • Improved support for object-oriented programming

    SQL:2008 and SQL:2011 (2008-2011)
    • SQL:2008 focused on:
      • Temporal data support
      • Periodic data types
      • Improved OLAP (Online Analytical Processing) capabilities
    • SQL:2011 added:
      • Temporal tables
      • Row pattern recognition
      • Improved security features

    SQL:2016 and beyond (2016-present)
    • SQL:2016 introduced:
      • JSON support
      • Row value expressions
      • Improved error handling
    • Future developments focus on:
      • Improved support for machine learning and data science
      • Enhanced data types (e.g., spatial, graph)
      • Continued performance optimizations

    Throughout its evolution, SQL has become a widely adopted standard for managing relational databases, with ongoing refinements and additions to support emerging needs and technologies.

  2. Question:What is SELECT statement?

    Answer: The SELECT statement lets you select a set of values from a table in a database. The values selected from the database table would depend on the various conditions that are specified in the SQL query.

  3. Question: How can you compare a part of the name rather than the entire name?

    Answer:
    SELECT * FROM people WHERE empname LIKE '%ab%' 
    

  4. Question: What is the INSERT statement?

    Answer: The INSERT statement lets you insert information into a database.

  5. Question: How do you delete a record from a database?

    Answer: Use the DELETE statement to remove records or any particular column values from a database.

  6. Question: How could I get distinct entries from a table?

    Answer: The SELECT statement in conjunction with DISTINCT lets you select a set of distinct values from a table in a database. The values selected from the database table would of course depend on the various conditions that are specified in the SQL query.
    Example
    SELECT DISTINCT empname FROM emptable
    

  7. Question: How to get the results of a Query sorted in any order?

    Answer: You can sort the results and return the sorted results to your program by using ORDER BY keyword thus saving you the pain of carrying out the sorting yourself. The ORDER BY keyword is used for sorting.
    SELECT empname, age, city FROM emptable
    ORDER BY empname
    

  8. Question: How can I find the total number of records in a table?

    Answer: You could use the COUNT keyword , example
    SELECT COUNT(*) FROM emp WHERE age>40
    

  9. Question:What is GROUP BY?

    Answer:
    The GROUP BY keywords have been added to SQL because aggregate functions (like SUM) return the aggregate of all column values every time they are called. Without the GROUP BY functionality, finding the sum for each individual group of column values was not possible.

  10. Question: What is the difference among "dropping a table", "truncating a table" and "deleting all records" from a table
    1. Dropping:(Table structure  + Data are deleted), Invalidates the dependent objects Drops the indexes
    2. Truncating: (Data alone deleted), Performs an automatic commit, Faster than delete
    3. Delete: (Data alone deleted), Does not perform automatic commit

Collect your data as if your life depends on it

Sometimes your life does depend on how you collect your data. Time series data provides many such serious examples. But let us begin with something less life threatening, such as: where would you like to spend your vacation?
Suppose you have been living in Seattle, Washington for two years. You have enjoyed a lovely summer, but as the season moves into October, you are not looking forward to what you expect will once again be a gray, chilly, and wet winter. As a break, you decide to treat yourself to a short holiday in December to go someplace warm and sunny. Now begins the search for a good destination. You want sunshine on your holiday, so you start by seeking out reports for rainfall in potential vacation places. Reasoning that an average of many measurements will provide a more accurate report than just checking what is happening at the moment, you compare the yearly rainfall average for the Caribbean country of Costa Rica (about 196 cm) with that of the South American coastal city of Rio de Janeiro, Brazil (117cm). Seeing that Costa Rica gets almost twice as much rain per year on average than Rio de Janeiro, you choose the Brazilian city for your December trip and end up slightly disappointed when it rains all four days of your holiday.

SEMrush Software