Database Joins

By Chris Smith

Another thing we can do to make this easier is to use a table alias. This is a "shortcut" to make our queries easier to read.

SELECT * FROM newsitem n INNTER JOIN authors a ON n.authorid=a.authorid;

We use "n" instead of "newsitem" and "a" instead of "authors". In this example we don't see much difference but if we selectively pick out our fields:

SELECT n.newsid, n.newstitle, n.newscontent, a.username, a.firstname, a.lastname FROM newsitem n INNER JOIN authors a ON n.authorid=a.authorid;

We can quickly see which field comes from which table and this saves us typing the whole table name!

In this particular case there's no real benefit from using table aliases, but try joining 3-4 tables together and you'll see a lot of use for it.

There you have it! Table joins and table aliases all in one go!

Pages: « Back  1 2 3 4  Next » 

Article Series

This article is part 4 of a 4 part series. Other articles in this series are shown below:
  1. An Introduction to Databases
  2. An Introduction to Database Variable Types
  3. Introduction to Database Indexes
  4. Database Joins



1 Response to "Database Joins"

Fill in the form below to leave a comment and share your thoughts.

 
mulugeta
said this on 18 Mar 2006 2:10:44 PM CST
It is good to achieve database education.



Leave a reply:
Your Name *: Email (private) *: Website:
Please copy the characters from the image below into the text field below. Doing this helps us prevent automated submissions.
Security Code: img