birbal Posted October 27, 2010 Share Posted October 27, 2010 i have two tables which i am joining by equi join. now i have a same column name in both table. i am using it with php. so when i am fetching it from database resource how can i refer a particular column from a particular table. Link to comment Share on other sites More sharing options...
[dx] Posted October 27, 2010 Share Posted October 27, 2010 SELECT somethingFROM somewhereWHERE something=value Link to comment Share on other sites More sharing options...
birbal Posted October 27, 2010 Author Share Posted October 27, 2010 SELECT somethingFROM somewhereWHERE something=valuenot so...i am not asking for query syntax. i meantable1 has a column name borntable2 has a column name born toonow i did equi join to both table. so new joined table has two column same name(born)$res=mysql_query($qry);$row=$mysql_fetch_assoc($res);now how can i get particularly table1 column born?$row['born'] as both field name is born in joined table Link to comment Share on other sites More sharing options...
[dx] Posted October 27, 2010 Share Posted October 27, 2010 Can't get it.. Explain.. Link to comment Share on other sites More sharing options...
justsomeguy Posted October 27, 2010 Share Posted October 27, 2010 You need to use an alias, which means you need to list each column out. I'm not sure if there's another way to give an entire table an alias that applies to all columns. e.g.:SELECT t1.name AS table1_name, t2.name AS table2_name ...You only need to list the table prefix if the field is in both tables. Link to comment Share on other sites More sharing options...
[dx] Posted October 27, 2010 Share Posted October 27, 2010 Oh, that was.. :S Link to comment Share on other sites More sharing options...
birbal Posted October 27, 2010 Author Share Posted October 27, 2010 You need to use an alias, which means you need to list each column out. I'm not sure if there's another way to give an entire table an alias that applies to all columns. e.g.:SELECT t1.name AS table1_name, t2.name AS table2_name ...You only need to list the table prefix if the field is in both tables.thanks it is solved now. i tried that table alias before but it was too returning same column name. which is ok at mysql but it was creating trouble at the php fetching time.had to give alias to all common tables. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.