0

I have to create an sql code to combine all the tables but when im using join, its creating another instance of the same column that's existing in both tables along with the column that is not. How can i only get the column that is not in table 1?

For example In table 1 I have

  • FORMID
  • STATUS
  • TITLE
  • DESCRIPTION

In table 2 I have

  • HSID
  • FORM ID

when I use join I get the following output:

FORMID - STATUS - TITLE - DESCRIPTION - HSID - FORMID_1

Eg. CODE:

SELECT * 
FROM PROJECT_FORM 
JOIN ASSIGNMENT
    ON PROJECT_FORM.FORMID=ASSIGNMENT.FORMID
1
  • some of the columns in right table only have values that will have to repeat based on the id in left table. im not sure if i can just list them all. for example: in table 1; i have formid in table 2: i have form id and hsid i want to know how to call hsid into the left table based on whichever value there is in formid in table 1 i hope im able to explain it correctly
    – raj
    Jan 13, 2020 at 21:14

1 Answer 1

3

You have to specifically list the columns you are interested in, rather than simply stating *

The first table can remain like this: SELECT PROJECT_FORM.*, … then you list the columns you require from the other table one by one.

SELECT PROJECT_FORM.*, ASSIGNMENT.HSID
FROM PROJECT_FORM
JOIN ASSIGNMENT ON PROJECT_FORM.FORMID=ASSIGNMENT.FORMID
3
  • some of the columns in right table only have values that will have to repeat based on the id in left table. im not sure if i can just list them all. for example: in table 1; i have formid in table 2: i have form id and hsid i want to know how to call hsid into the left table based on whichever value there is in formid in table 1 i hope im able to explain it correctly.
    – raj
    Jan 13, 2020 at 21:03
  • I'm afraid I'm not sure I understand the issue. Your JOIN takes care of that, pulling in the correct rows from the other table. Of course keep that part as you originally listed in your question. I'm editing my answer to include that.
    – fds
    Jan 13, 2020 at 21:19
  • Thank you! I got it.
    – raj
    Jan 14, 2020 at 16:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.