Selecting Fields With the Same Name
I had two people ask me the same question today so I thought I'd share this. The dilemma occurs when joining two or more tables where a field name is the same in those tables. For example, you have a blog table with an id field and a comments table with an id field. If you just did a
SELECT * while joining those two tables, you can't use the table identifier to grab the field name (E.g:
$rs['blog.id'] won't work).
If you're using MySQL, the way around this is to specify the field names manually and creating aliases for anything that would be a duplicate.
SELECT blog.id AS blog_id, comment.id AS comment_id, blog.title, blog.description, comment.text FROM [...]
If you're using MS SQL Server user, there's a quick shortcut where you can include all fields using the asterisk (*) and still create aliases for the other fields. Keep in mind, this will return blog_id AND blog.id.
SELECT blog.id AS blog_id, comment.id AS comment_id, * FROM [...]
I'm of the school of "return only what you need from the database" and would avoid using the asterisk selector in any case.