mylo Posted November 10, 2008 Share Posted November 10, 2008 Hello, i've got two tables which i want to "SELECT * " and JOIN, but they have some fields named with the same column name. When i execute the select the fields overlap and i can't tell them apart. Now, is there a way to prevent this (except of using unique names for fields, of course)? Maybe i can prefix the columns in question with the table name on-the-fly. Quote Link to comment https://forums.phpfreaks.com/topic/132134-solved-prefix-column-names-with-table-on-select-join/ Share on other sites More sharing options...
rhodesa Posted November 10, 2008 Share Posted November 10, 2008 the best way is to have unique names for each column...but you can also do it the manual way: SELECT t1.id AS t1_id, t2.id AS t2_id FROM .... INNER JOIN ..... Quote Link to comment https://forums.phpfreaks.com/topic/132134-solved-prefix-column-names-with-table-on-select-join/#findComment-686703 Share on other sites More sharing options...
mylo Posted November 10, 2008 Author Share Posted November 10, 2008 Well, this works, but i need to know the overlapping column names. I thought there is a more general way to prevent name collision, maybe a way to have all column names the table name as prefix. Quote Link to comment https://forums.phpfreaks.com/topic/132134-solved-prefix-column-names-with-table-on-select-join/#findComment-686716 Share on other sites More sharing options...
rhodesa Posted November 10, 2008 Share Posted November 10, 2008 'auto prefixing'...not that i'm aware of you can try mysql_fetch_row(), which will return a numerical array (therefore no collisions), and then mysql_field_name() and mysql_field_table() to tell where the column comes from Quote Link to comment https://forums.phpfreaks.com/topic/132134-solved-prefix-column-names-with-table-on-select-join/#findComment-686721 Share on other sites More sharing options...
mylo Posted November 10, 2008 Author Share Posted November 10, 2008 That works. Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/132134-solved-prefix-column-names-with-table-on-select-join/#findComment-686745 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.