Thursday, April 12, 2012

Joining Three or More Tables

Although each join specification joins only two tables, FROM clauses can contain multiple join specifications. This allows many tables to be joined for a single query.
The titleauthor table of the pubs database offers a good example of a situation in which joining more than two tables is helpful. This Transact-SQL query finds the titles of all books of a particular type and the names of their authors:
USE pubs
SELECT a.au_lname, a.au_fname, t.title
FROM authors a INNER JOIN titleauthor ta
   ON a.au_id = ta.au_id JOIN titles t
   ON ta.title_id = t.title_id
WHERE t.type = 'trad_cook'
ORDER BY t.title ASC
Here is the result set:
au_lname          au_fname             title      
----------------- -------------------- ---------- 
Blotchet-Halls    Reginald             Fifty Years in Buckingham Palace 
   Kitchens
Panteley          Sylvia               Onions, Leeks, and Garlic: 
   Cooking Secrets of the Mediterranean
O'Leary           Michael              Sushi, Anyone?
Gringlesby        Burt                 Sushi, Anyone?
Yokomoto          Akiko                Sushi, Anyone?

(5 row(s) affected)
Notice that one of the tables in the FROM clause, titleauthor, does not contribute any columns to the results. Also, none of the joined columns, au_id and title_id, appear in the results. Nonetheless, this join is possible only by using titleauthor as an intermediate table.
The middle table of the join (the titleauthor table) can be called the translation table or intermediate table, because titleauthor is an intermediate point of connection between the other tables involved in the join.
When there is more than one join operator in the same statement, either to join more than two tables or to join more than two pairs of columns, the join expressions can be connected with AND or with OR.

http://msdn.microsoft.com/en-us/library/aa213227%28v=sql.80%29.aspx

Tuesday, April 3, 2012

What's the difference between a URI and a URL?


From RFC 3986:
A URI can be further classified as a locator, a name, or both. The term "Uniform Resource Locator" (URL) refers to the subset of URIs that, in addition to identifying a resource, provide a means of locating the resource by describing its primary access mechanism (e.g., its network "location"). The term "Uniform Resource Name" (URN) has been used historically to refer to both URIs under the "urn" scheme [RFC2141], which are required to remain globally unique and persistent even when the resource ceases to exist or becomes unavailable, and to any other URI with the properties of a name.
So any URL is a URI, but some URIs aren't URLs, they're URNs instead. Except the ones which are both URNs and URLs.
Clear as mud?
EDIT: Note also Roger Pate's clearer answer. (I can't delete this answer as it's accepted, nor do I think it's worth just copying his text into here, but please read it...)