Combining 3 tables

  • Thread starter Thread starter Tim
  • Start date Start date
T

Tim

I have two tables, and one giving extra information about this
combination.

When I use the query "SELECT * FROM TableA,TableB" I get the desired
records, but I want to ignore the records that already exist in TableC
and show a specific column of TableC instead otherwise empty.

I've been trying subqueries and joins for a few days now to get the
desired result, but nothing will give me what I'm looking for. Maybe my
knowlegde on SQL is too limited, so please enlight me...

TableA
-----------
1 - First A
2 - Second A
3 - Third A

TableB
----------
1 - First B
2 - Second B
3 - Third B

TableC
----------
1 - 1 - 1 - FirstAFirstB
2 - 1 - 3 - FirstAThirdB


With the basic query I would get

1 - First A - 1 - First B - empty
1 - First A - 2 - Second B - empty
1 - First A - 3 - Third B - empty

2 - Second A - 1 - First B - empty
2 - Second A - 2 - Second B - empty
2 - Second A - 3 - Third B - empty

3 - Third A - 1 - First B - empty
3 - Third A - 2 - Second B - empty
3 - Third A - 3 - Third B - empty

What I want to become is

1 - First A - 1 - First B - FirstAFirstB
1 - First A - 2 - Second B - empty
1 - First A - 3 - Third B - FirstAThirdB

2 - Second A - 1 - First B - empty
2 - Second A - 2 - Second B - empty
2 - Second A - 3 - Third B - empty

3 - Third A - 1 - First B - empty
3 - Third A - 2 - Second B - empty
3 - Third A - 3 - Third B - empty

Many thanks in advance!
 
Tim said:
I have two tables, and one giving extra information about this
combination.

When I use the query "SELECT * FROM TableA,TableB" I get the desired
records, but I want to ignore the records that already exist in TableC
and show a specific column of TableC instead otherwise empty.

I've been trying subqueries and joins for a few days now to get the
desired result, but nothing will give me what I'm looking for. Maybe
my knowlegde on SQL is too limited, so please enlight me...

TableA
-----------
1 - First A
2 - Second A
3 - Third A

TableB
----------
1 - First B
2 - Second B
3 - Third B

TableC
----------
1 - 1 - 1 - FirstAFirstB
2 - 1 - 3 - FirstAThirdB


With the basic query I would get

1 - First A - 1 - First B - empty
1 - First A - 2 - Second B - empty
1 - First A - 3 - Third B - empty

2 - Second A - 1 - First B - empty
2 - Second A - 2 - Second B - empty
2 - Second A - 3 - Third B - empty

3 - Third A - 1 - First B - empty
3 - Third A - 2 - Second B - empty
3 - Third A - 3 - Third B - empty

What I want to become is

1 - First A - 1 - First B - FirstAFirstB
1 - First A - 2 - Second B - empty
1 - First A - 3 - Third B - FirstAThirdB

2 - Second A - 1 - First B - empty
2 - Second A - 2 - Second B - empty
2 - Second A - 3 - Third B - empty

3 - Third A - 1 - First B - empty
3 - Third A - 2 - Second B - empty
3 - Third A - 3 - Third B - empty

Many thanks in advance!

Is there any relationship between the data in the tables?
 
Only in the third table, which holds an identifier for each the two
first tables...


Joseph Meehan schreef:
 
Tim said:
Only in the third table, which holds an identifier for each the two
first tables...

IF (that's a big if) I understand this right, I can't see how you can do
what you want without setting up a relationship to the third table.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top