mcrmg
asked on
Query syntax
Hi,
I need help from EEs to get the the query. I have two tables.
Table A has ID that can link to Table B's ID.
I need to bring everything from Table A without duplication. As you can see in Table B, it contains everything from TableA
and some with duplications.
The logic is to bring everything from Table A and PID from Table B
The end result should look like this
ID PID
1545043 1-001
10018849 8-001
10038557 32
10032746
10555277 10-001
10010026 6-001
10039886 58-5
10037757
10734379 85
If there is no duplication in Table B, get the PID; if there is duplication in Table B, get the one reads "001"
thanks
test.xlsx
I need help from EEs to get the the query. I have two tables.
Table A has ID that can link to Table B's ID.
I need to bring everything from Table A without duplication. As you can see in Table B, it contains everything from TableA
and some with duplications.
The logic is to bring everything from Table A and PID from Table B
The end result should look like this
ID PID
1545043 1-001
10018849 8-001
10038557 32
10032746
10555277 10-001
10010026 6-001
10039886 58-5
10037757
10734379 85
If there is no duplication in Table B, get the PID; if there is duplication in Table B, get the one reads "001"
thanks
test.xlsx
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I meant to note this in my original post.
There is no way given the data provided to determine if an outer join is needed or not. The wording of the question says it would be needed, but the data isn't conclusive. I left it as inner join because I don't like to use an outer join if it isn't needed.
There is no way given the data provided to determine if an outer join is needed or not. The wording of the question says it would be needed, but the data isn't conclusive. I left it as inner join because I don't like to use an outer join if it isn't needed.
@johnsone
I agree, it wasn't initially clear to me either, but implied I think through the expected result. So, I believe you chose correctly.
I agree, it wasn't initially clear to me either, but implied I think through the expected result. So, I believe you chose correctly.
ASKER
thank you very much
The term duplicate in SQL applies to the whole row, so I do not see any "duplications" in your tableB.
There is information in TableB that does not exist in TableA:
Open in new window
but an INNER JOIN will ignore any rows where the IDs are unmatchedOpen in new window
and as johnsone identifies using minimum will produce this result:Open in new window