Category Archives: SQL

Next Time

NULL values in SQL ¨  Additional SQL join operations 🞑 Natural join 🞑 Outer joins ¨  SQL views
Continue reading

Updating Tables (2)

¨  Values in UPDATE can be arithmetic expressions 🞑 Can refer to any attribute in table being updated ¨  Example: 🞑 Add 2%…
Continue reading

Updating Tables

¨  SQL also has an UPDATE command for modifying existing tuples in a table 🞑General form: UPDATE table SET attel=vall, attr2=va12, . .…
Continue reading

Deleting Tuples

SQL DELETE command can use a WHERE clause DELETE FROM table; 🞑 Deletes all rows in the table DELETE FROM table WHERE ...;…
Continue reading

More Data Manipulation Operations

¨  SQL provides many other options for inserting, updating, and deleting tuples All commands support SELECT-style syntax ¨  Can insert individual tuples into…
Continue reading

Aggregates of Aggregates

¨  Always take note when computing aggregates of aggregates! “Find the largest total account balance of any branch.” 🞑 Two nested aggregates: max…
Continue reading

Using Derived Relations

¨  More typical is a query against aggregate values Example: “Find the largest total account balance of any branch.” 🞑 Need to compute…
Continue reading

Derived Relation Syntax

¨  Subquery in FROM clause must be given a name 🞑 Many DBMSes also require attributes to be named SELECT customer_city, num_customers FROM…
Continue reading

HAVING vs. Nested Query

“Find all cities with more than two customers living in the city.” SELECT customer_city, COUNT(*) AS num_customers FROM customer GROUP BY customer_city HAVING…
Continue reading

Subqueries in FROM Clause

¨  Often need to compute a result in multiple steps Can query against a subquery’s results 🞑 Called a derived relation ¨  A…
Continue reading