Query data from multiple tables using SQL
P粉151720173
P粉151720173 2024-04-03 16:00:37
0
1
336

Suppose we have three tables:

Table 1

|     c_id          |   categories     |   
|-------------------|------------------|
|      7            |       a          |     
|      4            |       b          |     
|      3            |       c          |

Table 2

|     c_id          |   dup_id     |   
|-------------------|--------------|
|       9           |     10       |     
|       5           |      3       |     
|       6           |      2       |  

table 3

|     c_id          |  description |   
|-------------------|--------------|
|      22           |     xxxx     |     
|       5           |     yyyy     |     
|      11           |     zzzz     |  

Suppose if some values ​​in dup_id in Table1 are equal to dup_id in Table2, then we can find the dup_id# corresponding to dup_id ##, and use it to find description in Table3. What's the best way to do this?

Output:

|     c_id          |  description |   
|-------------------|--------------|    
|       5           |     yyyy     |

P粉151720173
P粉151720173

reply all(1)
P粉288069045

It seems to be a direct connection of 3 tables:

select Table2.c_id, description
from Table1
join Table2 on Table1.c_id = Table2.dup_id
join Table3 on Table2.c_id = Table3.c_id;
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template