I take the content of two table performing a join like this:
SELECT * FROM table1
INNER JOIN table2
ON table1.code = table2.code
Now the table1
have a structure like this:
|CODE|Info|Created |Modified
|R789|Home|21/03/2016 10:00 |21/03/2016 15:00
and table2
:
|CODE|Description|Created |Modified
|R789|Testing| 21/03/2016 10:05 | 21/03/2016 18:10
Now the problem is that the query return this result:
"Code":"RB01",
"Info":Home,
"Created":"21/03/2016 10:05",
"Modified":"21/03/2016 18:10",
"Description":"Testing"
How you can see I have created
and modified
that is identical in the two tables. So the query discard the created
and modified
of table1
.. this is a problem for me, how can I avoid this situation?
You need to use the AS keyword to create an alias for the column name. Consider this:
SELECT t1.CODE, t1.Info, t1.Created AS t1Created, t1.Modified AS t1Modified, t2.Description, t2.Created AS t2Created, t2.Modified AS t2Modified
FROM table1 t1
INNER JOIN table2 t2 ON t1.CODE = t2.CODE
This will return
"Code":"RB01",
"Info":Home,
"t1Created":"21/03/2016 10:00",
"t1Modified":"21/03/2016 15:00",
"Description":"Testing",
"t2Created":"21/03/2016 10:05",
"t2Modified":"21/03/2016 18:10",