在SQL查询中使用空表
我创建了一个新的SQL表,它有两列[Lot_no,Comment],为空在SQL查询中使用空表,sql,sql-server,Sql,Sql Server,我创建了一个新的SQL表,它有两列[Lot_no,Comment],为空 |Lot_No|comment| 我有另一个两列的表[Lot\u no,Product\u Code],它有值 |Lot_No|Product_Code| |1 |2304| |2 |2307| |3 |2317| |4 |2308| 问题: 我想创建一个SQL查询,在其中检索一些[Lot\u No | Product\u code | Comment]的[Lot\u No],但由于第
|Lot_No|comment|
我有另一个两列的表[Lot\u no,Product\u Code],它有值
|Lot_No|Product_Code|
|1 |2304|
|2 |2307|
|3 |2317|
|4 |2308|
问题:
[Lot\u No | Product\u code | Comment]
的[Lot\u No]
,但由于第一个表中没有可用于注释的数据,所以在Comment retrieved列中应该返回null一个简单的
左连接应该可以做到这一点。也许是这样的:
Select A.Lot_No
,A.Product_Code
,B.Comment
From YourTable A
Left Join YourCommentTable B
on A.Lot_No = B.Lot_No
Where A.Lot_No = 3 -- for example
插页
Insert Into YourCommentTable (Lot_No,Comment) values (4,'Some new comment')
我假设“旧语法”指的是ansi之前的旧语法。试试这个:
Select A.Lot_No
,A.Product_Code
,B.Comment
From YourTable A, YourCommentTable B
Where A.Lot_No = 3 -- for example
And A.Lot_No *= B.Lot_No
非常感谢,因为它正在工作。你能在上面的查询中帮助我使用较旧的左连接语法吗?因为我的most查询具有较旧的连接语法,如果我使用ANSI语法,它会令人困惑。你能在上面的查询中帮助我使用较旧的左连接语法吗?因为我的most查询具有较旧的连接语法,如果我使用ANSI语法,它会令人困惑syntax@SauravSingh你觉得呢“旧语法”是什么意思?“左连接”并没有什么古老的含义,因为我们看不到您所指的查询,所以我们无法就、,。