SQL query join

Hello,

I'm having trouble with this query. I have two tables:

tableA
ID      Type  
1      apple
2      orange
3      pear

tableB
1      apple
2      orange

The ID is joined and I want it to return all the records in tableA regardless like this:

ID      TypeFromTableA     TypeFromTableB
1      apple                       apple
2      orange                       orange
3      pear

Thanks,
Joel
Genius123Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Saurabh Singh TeotiaCommented:
You can use this to do what you are looking for...

select tb1.id,tb1.type,tb2.type
from tablea tb1
left join tableb tb2 on tb1.id=tb2.id

Open in new window


Saurabh...
0
Jeff DarlingDeveloper AnalystCommented:
another way is a full join.

select A.id,a.mytype,b.mytype from #tableA A
full join #tableB B on A.ID = B.ID

Open in new window

0
Tj aCommented:
I would probably also use a full join
SELECT tableA.id, tableA.type, tableB.type
FROM tableA
FULL OUTER JOIN tableB
ON tableA.id = tableB.id;

Open in new window

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Genius123Author Commented:
I get an error on FULL OUTER JOIN.
It says "Syntax error in FROM clause."

I'm running this from Access.  Any ideas?
0
Saurabh Singh TeotiaCommented:
Did you try the query which i posted??
0
Dale FyeCommented:
Access doesn't do FULL JOIN
0
Jeff DarlingDeveloper AnalystCommented:
Please disregard my suggestion,  didn't notice this was for Microsoft Access since it is posted in MS SQL Server area.

In that case, I have to go with left join as indicated by Saurabh Singh Teotia.

SELECT Table1.ID, Table1.myType, Table2.myType
FROM Table1 LEFT JOIN Table2 ON Table1.ID = Table2.ID;

Open in new window

0
Genius123Author Commented:
Thank you both, that worked!  For some reason, Saurabh's solution didn't work quite as well as Jeff's, but I could have been doing something wrong.  Jeff's code worked after I changed the table names to real names.
0
Saurabh Singh TeotiaCommented:
Geninus,

The difference between me and jeff solution is an Semicolon at the end since in order to run the query in access it need to have an Semicolon in the end.. So if you add that it will work...

select tb1.id,tb1.type,tb2.type
from tablea tb1
left join tableb tb2 on tb1.id=tb2.id;

Open in new window


Again not for points but i'm not in agreement the way this question as closed and solution has been accepted as i don't see any significant value or changes suggested from my original solution which i posted...

Saurabh...
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Genius123Author Commented:
Sorry, I can't figure out how to change who has the solution.  Is there a way to do that?
0
Dale FyeCommented:
Yes,

Click the Request Attention hyperlink at the bottom right of your original post.  Then, indicate to the moderators that you want to reallocate points.
0
Genius123Author Commented:
Thank you.  Everyone was very prompt with suggestions to help me.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.