I want to know how I can join one field of an INNER JOIN table in a SELECT QUERY.
Here's what i got so far: In this query my result would be NameA, NameB and idC, but i want to join tableA and tableC reference as shown in the image schema.
SELECT table_A.idC, table_A.nameA, table_B.nameB
FROM table_Ref
INNER JOIN table_A ON table_Ref.idA=tableA.idA
INNER JOIN table_B ON table_Ref.idB=tableB.idB;
My wanted result would be nameA,NameB, and NameC using the idC field in table_A to know which nameC belongs to that idC.
I hope you can help me or give me a reference of this topic :)!
2 Answers 2
you can join on table_C
SELECT nameC, nameA, nameB
FROM table_Ref r
INNER JOIN table_A a ON r.idA=a.idA
INNER JOIN table_B b ON r.idB=b.idB
INNER JOIN table_C c ON a.idC=c.idC;
-
1(I suggest that "inherit" is not the proper term for database-speak.)Rick James– Rick James2020年02月25日 07:12:28 +00:00Commented Feb 25, 2020 at 7:12
-
or if there isnt always a rows to join to in table_C, you can do outer joinBob Klimes– Bob Klimes2020年02月26日 22:06:03 +00:00Commented Feb 26, 2020 at 22:06
In this case you can use FULL OUTER JOIN
in INNER JOIN
what can happen is to have blanck fields in the final table due to data that are not in all tables
Explore related questions
See similar questions with these tags.