how to join 3 relational tables

Posted by orioncabbar on Stack Overflow See other posts from Stack Overflow or by orioncabbar
Published on 2010-12-23T14:23:25Z Indexed on 2010/12/25 2:54 UTC
Read the original article Hit count: 228

Filed under:
|
|

Hello there,

how to join 3 relational tables with the structure:

t1 | id
t2 | id | rating
t3 | source_id | relation

t3 stores the data of a field which t1 and t2 uses both. so source_id field can be t1's id or t2's id.

input  : t1 id
output : t2 rating

an example:

**t1**

id |
---------
42 |

**t2**

id | rating  
-------------
37 | 9.2

**t3**

id | source_id
--------------
42 | 1
37 | 1
26 | 2
23 | 1

what i want is to get 9.2 output with 42 input.

can you do that in one sql query?

© Stack Overflow or respective owner

Related posts about mysql

Related posts about join