Showing posts with label query. Show all posts
Showing posts with label query. Show all posts

Sunday, 22 November 2020

Describe the four clauses in the syntax of a simple SQL retrieval query.

 Question: 4.4. Describe the four clauses in the syntax of a simple SQL retrieval query. Show what type of constructs can be specified in each of the clauses. Which are required and which are optional?

Solution:

  1. SELECT
  2. FROM
  3. WHERE
  4. ORDER BY
  5. Limit

SELECT

List of attribute names to be received by the query

FROM

The tables that these attributes with be retrieved from

WHERE

Conditional boolean expression to identify certain tuples to be retrieved (optional)

ORDER BY

Attribute list to order the result by (optional)

LIMIT BY 

This is used to limit the number of rows (optional)

How do the relations (tables) in SQL differ from the relations defined formally

Questions 4.1. How do the relations (tables) in SQL differ from the relations defined formally in Chapter 3? Discuss the other differences in terminology. Why does SQL allow duplicate tuples in a table or in a query result?

Solution:  SQL allows a table to have more than one tuple that are identical in all their attribute values while others don't

The reasons why SQL allows duplicate tuples are

  • Duplicate elimination is an expensive operation
  • User may want to see duplicate tuples in the result of query