Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

Duplicate Columns in Recordset

Guest
May 23, 2009 May 23, 2009

I created a recordset in Bindings with a SQL statement that LEFT JOINs three tables in DW CS4.  All three tables use id as a column name for the key.  With this query id appears twice in the Recordset list.  In the SQL query they're qualified (e.g., t1.id and t2.id)  I can figure out which is which by the order of appearance in the Recordset list and the php page works fine.  Is there some way to have a qualified name like in the SELECT?  Without a qualification it makes the code confusing:

<td><?php echo $row_VCH['id']; ?></td>
<td><?php echo $row_VCH['name']; ?></td>
<td><?php echo $row_VCH['id']; ?></td>

...

Is there a better way to handle these types of queries instead of manually entering them?

Thanks,

Curt

TOPICS
Server side applications
421
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 24, 2009 May 24, 2009

I prefer to name my columns so they're easy to distinguish in a database query and result. If you're early enough on in your project, it might be a good idea to rename the columns. However, there is a useful technique that you can use, even if you don't change the column names: aliases.

SELECT t1.id AS t1_id, t2.id AS t2_id

FROM t1, t2

This returns the values as t1_id and t2_id. You don't need to use this combination of table and column name, you could use "apples" and "bananas" or any other name that identifies the columns for you.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 24, 2009 May 24, 2009
LATEST

Thanks for the response David.  It occurred to me that aliases might be the answer.  As it turns out, the code wasn't working without them.  I wasn't looking closely enough at the results.  Using aliases fixed it.  I've only be using PHP and MySQL for a day so it's definately early in the project.  I agree giving a column a name that is unique across the DB would eliminate the problem.  It just bothers me to have add such qualifications when the table name should be sufficient.  I don't recall having this problem with other SQL interfaces, but it's been awhile.

Curt

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines