Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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