question

JWC avatar image
JWC asked

Please help me to make a SQL query.


Here are two tables, table A and B.

I would like to add two columns of table A (PERSON_ID and MAIN_SICK) to table B, referring to the KEY_SEQ columns in both tables (table A and B).

Can you plz help me to build a SQL query?

I want the exactly same table like "Result".

Thank you!

query-plan
tables.jpg (220.6 KiB)
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

JohnM avatar image JohnM commented ·

What have you tried so far?

0 Likes 0 ·

1 Answer

·
lokeshlehkara avatar image
lokeshlehkara answered

This is simple join. I believe you are fairly new to SQL. Enjoy!!!!

SELECT A.Person_ID,A.Key_Seq,A.Main_Sick,B.Seq_No,B.Drug 
FROM TABLE_A as A
INNER JOIN
TABLE_B as B ON A.Key_Seq = B.Key_Seq
2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

JWC avatar image JWC commented ·

Thank you, lokeshlehkara!

0 Likes 0 ·
WRBI avatar image WRBI commented ·

Might be worth pointing the OP to some tutorials/MSDN around JOINS so they can learn from your example.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.