gpt4 book ai didi

字段名相同时的SQL连接

转载 作者:行者123 更新时间:2023-11-29 04:13:30 24 4
gpt4 key购买 nike

我在节点和 url_alias 中都有字段“语言”。当我进行转储时,第二个“语言”变量会覆盖第一个。如何识别这两个变量?

$string =   "SELECT * FROM {node} as node " .
" LEFT JOIN {url_alias} as url " .
" ON url.src = CONCAT('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);

最佳答案

SELECT 子句中明确指定列名,而不是使用 *,并为任何重复的列名指定一个别名。例如,

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

关于字段名相同时的SQL连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4280723/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com