1

I am trying to retrieve 'date_and_time' field from two different tables of a mysql database using join query. Since the field name in both tables are same, the key name in the return result of an associated array being overwritten by the new key. How to change the key name if it exists, or is there any possibility to add table name along with field name as a key of associative array.

2
  • Change the query: SELECT tableA.column AS yourColumnAlias, tableB.column as differentAlias ... Commented Sep 14, 2015 at 16:36
  • Thank u dude u save a lot it worked :) post it as an answer pls. Commented Sep 14, 2015 at 16:47

1 Answer 1

2

Ok, just for the people checking these post later: In SQL, tables & columns can be aliased: To fetch two columns which originally have the same name, it's easy to 'rename' them:

SELECT tableA.column AS yourColumnAlias, tableB.column as differentAlias FROM ...

will return a result-set in the form of

---------------------------------------------------------------------
|yourColumnAlias                     |differentAlias                |
|value from tableA.column            |value from tableB.column      |

P.S.: In complex Joins, this also helps to keep Queries readable, as Tables can also be aliased.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.