PostgreSQL & PHP Tutorials - Database Joins - Table Aliases

PostgreSQL »  Introduction to Database Joins
PostgreSQL »  Starting Out »  Introduction to Database Joins

Posted By Chris Smith Posted on 02 Apr 2006, 10:34 PM
Viewing page 4 of 4
« | Back | Next | »

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!
Viewing page 4 of 4
« | Back | Next | »

Avg Rating: 3
Vote Count: 9


              

  New Reply


good tutorial but the inner join are very slow realizzazione siti 08 Jun 2007 Reply
`-- Then you're missing an index or something. They should be quite fast. Chris Smith 16 Jun 2007 Reply


Want to post a comment? Fill in the details below.

Your Name  : 
Your Email  : 
Your Website  : 
Spam Check! Please answer this question  : 3 + 5 =
Comment