0

I have created a new SQL table of two column [Lot_no, Comment] which is empty.

|Lot_No|comment|

I have another table of two column [Lot_no, Product_Code] which has values.

|Lot_No|Product_Code|
|1     |2304|
|2     |2307|
|3     |2317|
|4     |2308|

Problem:

  1. I want to create a SQL query where I retrieve [Lot_No|Product_Code|Comment] for some [Lot_No] but since no data is available for comment in first table it should return null in comment retrieved column.

  2. Later I want to insert new row of Lot_No and comment in that empty table. How can I do this?

0

2 Answers 2

2

A simple LEFT JOIN should do the trick. Perhaps something like this:

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

For the Insert

Insert Into YourCommentTable (Lot_No,Comment) values (4,'Some new comment')
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks a lot as it is working. Can you please help me with older syntax of left join in the above query as my most query has older syntax of join and it will be confusing if i use ANSI syntax.
Can you please help me with older syntax of left join in the above query as my most query has older syntax of join and it will be confusing if i use ANSI syntax
@SauravSingh What do you mean by "older syntax"? There is nothing old about a "left join" and as we can't see your queries which you refer to, we cannot advise you on the,.
-1

I assume by 'older syntax' you mean the old pre-ansi syntax. Try this:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.