Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/63.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 sql将列添加到结果_Mysql_Sql_Sql Server - Fatal编程技术网

Mysql sql将列添加到结果

Mysql sql将列添加到结果,mysql,sql,sql-server,Mysql,Sql,Sql Server,因此,我希望将itemlookupcode添加到查询结果中。itemlookupcode位于item表中,但查询针对不同的表。这两个表都有itemdescription,但当我进行联接或左联接时,会得到重复的项 select * from [RAPurchaseOrderTransfer] where QtyDifference <> 0 and fromstoreid = 111 and DateCreated >= dateadd(dd, -30, GETDATE(

因此,我希望将itemlookupcode添加到查询结果中。itemlookupcode位于item表中,但查询针对不同的表。这两个表都有itemdescription,但当我进行联接或左联接时,会得到重复的项

select * 
from [RAPurchaseOrderTransfer] 
where QtyDifference <> 0 
and fromstoreid = 111 
and DateCreated >= dateadd(dd, -30, GETDATE())

您知道如何将item.lookupcode添加到结果中吗?

为了避免重复,您可以执行嵌套选择以获取itemlokupcode

使用MySQL时,limit 1将只返回1:

(select i.itemlookupcode from item i where i.itemdescription = r.itemdescription limit 1)
对于SQL Server,它将如下所示:

(select top 1 i.itemlookupcode from item i where i.itemdescription = r.itemdescription)
例如:

select 
r.*,
(select top 1 i.itemlookupcode from item i where i.itemdescription = r.itemdescription)
from [RAPurchaseOrderTransfer] r
where r.QtyDifference <> 0 
and r.fromstoreid = 111 
and r.DateCreated >= dateadd(dd, -30, GETDATE())

另一个表的名称是什么?如果您有一对多关系,您将获得此表中记录的重复副本。