| Database Joins | |
By Chris Smith |
Published
03/8/2006
|
Programming
|
Rating:
![]() ![]() ![]() ![]()
|
|
|
Table AliasesAnother 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! |
|
or 02-9262-7770 


Author/Admin)