PHP MySql Web Hosting

PHP and MySQL Web Development

,ch03.13605 Page 133 Wednesday, November 29, 2000 4:42

Filed under: SQL in a Nutshell — webmaster @ 10:38 am

,ch03.13605 Page 135 Wednesday, November 29, 2000 4:42 PM The JOIN clause In non-ANSI standard implementations, the join operation is performed in the WHERE clause (described in the section on WHERE clauses). In the ANSI SQL-92 standards, joins are performed in the JOIN clause of the query. These join methods are known as the theta style and the ANSI style of joins, respectively. To retrieve joined data from two or more tables, the tables first must share a meaningful relationship. The tables to be joined must possess a column or columns that share a common set of values that allow the tables to be meaningfully linked. This column, or columns, is called the join key or common key. Most but not all of the time, the join key is the primary key of one table and a foreign key in another table. As long as the data in the columns match, the join can be performed. In the PUBS database, both the employee table and the jobs table contain a job_id column. Thus, job_id is the common key between the employee and jobs tables. To perform a query using an ANSI-style join, list the first table and the keyword JOIN, followed by the table to be joined. Once the second table is typed in, type the keyword ON and the join condition that would have been used in the old style query. The following shows the original query now in ANSI style: SELECT e.emp_id, e.fname, e.lname, j.job_desc FROM employee AS e JOIN jobs AS j ON e.job_id = j.job_id ORDER BY e.fname, e.lname Join types These problems are solved by the use of join types in the ANSI style and the equal-asterisk ( =* ) combination for Microsoft SQL Server or plus-asterisk ( +* ) for Oracle in theta joins. The following list shows how to control this behavior in joins: Cross Join Specifies the complete cross product of two tables. For each record in the first table, all the records in the second table are joined, creating a huge result set. This command has the same effect as leaving off the join condition and is also know as a Cartesian Product. Cross joins are not advisable or recommended (currently supported by Microsoft SQL Server): — theta style SELECT e.emp_id, e.fname, e.lname, j.job_desc FROM employee e, Jobs j Statements SELECT 135

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost PHP Web Hosting services

No Comments

No comments yet.

RSS feed for comments on this post. TrackBack URI

Sorry, the comment form is closed at this time.

Powered by PHP MySQL Web Hosting