这是我的代码:
$sql = "SELECT table1.Insert_ID, table1.Type, table1.Date "
. "table2.User, table2.Date "
. "FROM Insert AS table1 "
. "INNER JOIN Contact AS table2 ON table2.Contact_ID = table1.Contact_ID";
$x =0;
while($row = odbc_fetch_array($res)){
$x++;
$values= ($x . ": " . " Insert ID:". $row['Insert ID'] . " Date Created: " . $row['Date'] . " Date Modified:" . "\n");
print($values);
}
我想要table1和table2中的Date,如果它们都具有相同的名称,我该如何继续检索数据?
答案 0 :(得分:1)
使用别名。
SELECT table1.Insert_ID, table1.Type, table1.Date as Date1 "
. "table2.User, table2.Date as Date2 "
. "FROM Insert AS table1 "
. "INNER JOIN Contact AS table2 ON table2.Contact_ID = table1.Contact_ID";
答案 1 :(得分:1)
列别名。
$sql = "SELECT table1.Insert_ID, table1.Type, table1.Date as T1Date "
. "table2.User, table2.Date as T2Date"
. "FROM Insert AS table1 "
. "INNER JOIN Contact AS table2 ON table2.Contact_ID = table1.Contact_ID";