Issue
I used a join query to retrieve values from two tables that have the same field name. How can i get the two fields value?
mysql_query("SELECT table1.Name, table2.Name
FROM table1
INNER JOIN table2
ON table1.Id=table2.userid
ORDER BY table1.Id DECS LIMIT 5")
With the above query, I need values from both table1.Name and table2.Name.
Solution
Give alias,
SELECT table1.Name as table1Name, table2.Name as table2Name
FROM table1
INNER JOIN table2
ON table1.Id=table2.userid
ORDER BY table1.Id DECS LIMIT 5
Note: Please, don't use mysql_*
functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO, or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial.
Answered By - Rikesh
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.