Wednesday, July 27, 2011

Political Statements/SQL Statements


Every movement has a database of its members and supporters. These days, everything is electronic and databases are now easier to maintain than ledgers.

Effective data management has been streamlined by the introduction of Structured Query Language (SQL, pronounced "sequel"), a relatively simple computer language that allows fast and powerful data manipulation.

From wikipedia:
The most common operation in SQL is the query, which is performed with the declarative SELECT statement. SELECT retrieves data from one or more tables, or expressions. Standard SELECT statements have no persistent effects on the database. Some non-standard implementations of SELECT can have persistent effects, such as the SELECT INTO syntax that exists in some databases.

Queries allow the user to describe desired data, leaving the database management system (DBMS) responsible for planning, optimizing, and performing the physical operations necessary to produce that result as it chooses.

A query includes a list of columns to be included in the final result immediately following the SELECT keyword. An asterisk ("*") can also be used to specify that the query should return all columns of the queried tables. SELECT is the most complex statement in SQL, with optional keywords and clauses that include:

  • The FROM clause which indicates the table(s) from which data is to be retrieved. The FROM clause can include optional JOIN subclauses to specify the rules for joining tables.

  • The WHERE clause includes a comparison predicate, which restricts the rows returned by the query. The WHERE clause eliminates all rows from the result set for which the comparison predicate does not evaluate to True.

  • The GROUP BY clause is used to project rows having common values into a smaller set of rows. GROUP BY is often used in conjunction with SQL aggregation functions or to eliminate duplicate rows from a result set. The WHERE clause is applied before the GROUP BY clause.

  • The HAVING clause includes a predicate used to filter rows resulting from the GROUP BY clause. Because it acts on the results of the GROUP BY clause, aggregation functions can be used in the HAVING clause predicate.

  • The ORDER BY clause identifies which columns are used to sort the resulting data, and in which direction they should be sorted (options are ascending or descending). Without an ORDER BY clause, the order of rows returned by an SQL query is undefined.
The following is an example of a SELECT query that returns a list of expensive books. The query retrieves all rows from the Book table in which the price column contains a value greater than 100.00. The result is sorted in ascending order by title. The asterisk (*) in the select list indicates that all columns of the Book table should be included in the result set:

SELECT * FROM Book WHERE price > 100.00 ORDER BY title
See, SQL at wikipedia.org

In the example above, the results would be rows of titles of every book in the database priced over one hundred dollars.

If you open-up the database of Tea Party supporters who have accounts at the Tea Party website, they will likely be listed as USERS. Each USER is a row and each row has many columns for information like email address, name, ZIP Code, religious affiliation, donation amounts, etc. Fields can be strings of text, Yes/No, Ratings, Numeric, Financial, etc.

When a Tea Party staff member wants to find all the tea party supporters in Park Slope, Brooklyn, she would enter:

SELECT * FROM users WHERE zip = 11215; ORDER BY user

This would return a list of all users in the database that live in ZIP Code 11215.


The geeks at thinkgeek.com have taken the SQL statement to a new level. Intended to be an observation about computer users, their SQL Query t-shirt can be interpreted many ways.

From your t-shirt to God's ear, this is the perfect embodiment of Tea Party collective intelligence.

The t-shirt query asks to return all those who have a clue greater than no clue. The results are zero.

In the database of Tea Party supporters, there is nobody with a clue!

Buy your thinkgeek SQL Style t-shirt here


Thanks to Eram for the heads-up!

No comments: