开发者

SQL join when a field name is the same

开发者 https://www.devze.com 2023-01-27 13:06 出处:网络
I have field \"language\" in both node and url_alias. When I do a dump, the second \"language\" variable overwrites the first one.

I have field "language" in both node and url_alias. When I do a dump, the second "language" variable overwrites the first one. How can I identify both variables?

$string =   "SELECT * FROM {node} as node " .
            " LEFT JOIN {url_alias} as url " .
            " ON url.src = CONCAT开发者_如何学Go('node/', node.nid) " .                
            " ORDER BY node.type , node.nid " ;

$result= db_query($string);
while ($row = db_fetch_object($result)){
echo $row->language;
var_dump($row);


Specify the column names explicitly in your SELECT clause rather than using *, and give any duplicate column names an alias. E.g.,

SELECT node.nid,
    node.language as NodeLanguage,
    url.language as UrlLanguage
FROM {node} as node 
LEFT JOIN {url_alias} as url  
ON url.src = CONCAT('node/', node.nid)                 
ORDER BY node.type , node.nid
0

精彩评论

暂无评论...
验证码 换一张
取 消