Robb Kerr wrote: > > I am attempting to hack a tutorial from the Zend site. I have found the > tutorial/project to be excellent, but I don't completely understand what's > being done in the following Query statement. > > //query database, assemble data for selectors > $Query = "SELECT s.ID, s.Name, a.Code " . > "FROM areacode a, state s " . > "WHERE a.State = s.ID " . > "ORDER BY s.Name, a.Code"; > if(!($DatabaseResult = mysql_query($Query, $DatabaseLink))) > { > print("The query failed!<br>\n"); > exit(); > } > > Please explain what's going on in this SELECT statement. I'm assuming that > the "s" in "s.ID", the "s" in "s.Name" and the "a" in "a.Code" are > variables referring to the table name. "ID", "Name" and "Code" are field > names in two different tables. But, I can't find a place where these > variables are initiated in the preceding code. > > I also don't understand what's going on in the FROM statement. "Areacode" > and "state" are table names. That I understand. What's with the "a" and "s" > following the table names? Is this where the variables are initiated?
Exactly. "a" and "s" are referring to the two tables and are assigned in the FROM clause. You could write the query also without the abbreviations. SELECT state.ID, state.Name, areacode.Code FROM areacode, state WHERE areacode.State = state.ID ORDER BY state.Name, areacode.Code Alexander -- PINO - The free Chatsystem! Available at http://www.pino.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php