Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MySql连接查询两个表_Mysql_Join - Fatal编程技术网

MySql连接查询两个表

MySql连接查询两个表,mysql,join,Mysql,Join,您好,我正在尝试使用mysql查询连接两个表,但无法检索数据 两个表是accountheader和accountheadermonths 查询: Select ah.AH_SUBNAME,ahm.AH_OPENINGBALANCE1 from erp_updated.accountheader ah,erp_updated.accountheader_months ahm where ah.AH_CODE =" " AND ahm.AH_CODE=" " ; 提前谢谢 请帮助连接两个表您应

您好,我正在尝试使用mysql查询连接两个表,但无法检索数据

两个表是accountheader和accountheadermonths

查询:

Select ah.AH_SUBNAME,ahm.AH_OPENINGBALANCE1 
from erp_updated.accountheader ah,erp_updated.accountheader_months ahm 
where ah.AH_CODE =" " AND ahm.AH_CODE=" " ;
提前谢谢
请帮助

连接两个表您应该有一个共同点来连接这两个表

Select ah.AH_SUBNAME,
       ahm.AH_OPENINGBALANCE1 
from   erp_updated.accountheader ah 
join
erp_updated.accountheader_months ahm 
on     ah.<col>=ahm.<col>
where  ah.AH_CODE =" " 
AND    ahm.AH_CODE=" " ;
选择ah.ah_子名称,
ahm.AH_开平衡1
从erp_updated.accountheader ah
参加
erp\u已更新。accountheader\u月ahm
啊。
其中ah.ah_CODE=“”
和ahm.ahu CODE=“”;

要连接两个表,您应该有一个公共接口来连接这两个表

Select ah.AH_SUBNAME,
       ahm.AH_OPENINGBALANCE1 
from   erp_updated.accountheader ah 
join
erp_updated.accountheader_months ahm 
on     ah.<col>=ahm.<col>
where  ah.AH_CODE =" " 
AND    ahm.AH_CODE=" " ;
选择ah.ah_子名称,
ahm.AH_开平衡1
从erp_updated.accountheader ah
参加
erp\u已更新。accountheader\u月ahm
啊。
其中ah.ah_CODE=“”
和ahm.ahu CODE=“”;

在任何联接查询中,必须指定联接多个表的条件。看起来,在您的案例中,AHU代码是关联两个表的关键。所以,查询将是

SELECT 
   ah.AH_SUBNAME,
   ahm.AH_OPENINGBALANCE1 
FROM
   erp_updated.accountheader ah, 
   erp_updated.accountheader_months ahm 
WHERE
   ah.AH_CODE=ahm.AH_CODE
   AND ah.AH_CODE =" ";

在任何联接查询中,都必须指定联接多个表的条件。看起来,在您的案例中,AHU代码是关联两个表的关键。所以,查询将是

SELECT 
   ah.AH_SUBNAME,
   ahm.AH_OPENINGBALANCE1 
FROM
   erp_updated.accountheader ah, 
   erp_updated.accountheader_months ahm 
WHERE
   ah.AH_CODE=ahm.AH_CODE
   AND ah.AH_CODE =" ";

这不是
join
而是首先尝试选择所有列,如
select ah.*,ahm.
。当您的联接工作时,您将指定精确的列。@alfasin:如果两个表中的
AH\u code
相同,这就是联接:联接不必使用
join
关键字。但这是一种有趣的方式。通常,我会看到
,其中ah.ah_code=“”和ah.ah_code=ahm.ah_code
。在任何情况下,问题都应该是预期的和实际的行为。这个问题缺少后者。当你这样做的时候会发生什么?错误返回了错误的数据?没有返回数据?诸如此类。不,它不被认为是一个
join
,除非您在
where
子句中添加以下条件:
和ah.ah_code=ahm.ah_code
这不是
join
它首先尝试选择所有列,如
select ah.*,ahm.
。当您的联接工作时,您将指定精确的列。@alfasin:如果两个表中的
AH\u code
相同,这就是联接:联接不必使用
join
关键字。但这是一种有趣的方式。通常,我会看到
,其中ah.ah_code=“”和ah.ah_code=ahm.ah_code
。在任何情况下,问题都应该是预期的和实际的行为。这个问题缺少后者。当你这样做的时候会发生什么?错误返回了错误的数据?没有返回数据?诸如此类。不,除非您在
where
子句中添加以下条件,否则它不被视为
join
和ah.ah_code=ahm.ah_code
您能用您尝试过的内容编辑您的问题吗?您能用您尝试过的内容编辑您的问题吗?