简体   繁体   English

来自不同表的数据具有相同的名称,如何检索数据?

[英]Data from different tables have the same name, how to retrieve data?

Here is my code: 这是我的代码:

$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);


}

I want Date from both table1 and table2, how do I proceed to retrieve the data if they both have the same name? 我想从table1和table2中获取Date,如果它们都具有相同的名称,如何继续检索数据?

Use an alias. 使用别名。

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";

Column aliases. 列别名。

$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";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM