开发者

Query 2 MYSQL tables + condition?

Format -> column.example_data

Table 1: id.1 | n开发者_开发技巧ame.Joe | etc.Some | ...Other | ...Data

Table 2: id.X | number.+1 123 555 9999 | useridfromtable1.1 -> Linking telefone with Joe

Table 3: id. X | number.+1 123 555 9999 | calls.55

I need a query that join the 3 tables and I only have the id (userid) from the table 1.

So, I need from userid -> grab the telephone -> from the telefone grab calls on table3.


TRY

SELECT t1.name,t1.id,t2.number,t3.calls
FROM table1 t1
INNER JOIN table2 t2 ON t2.useridfromtable=t1.id
INNER JOIN table3 t3 ON t3.number = t2.number


Try with something like:

SELECT t1.name,t1.id,t2.number,t3.calls
    FROM table1 t1
      INNER JOIN table2 t2 ON t2.t1_id = t1.id
        INNER JOIN table3 t3 ON t3.t2_id = t2.id

Where t1_id and t2_id are the fields that are referring the records in the parent tables. I recommend you to add an index on those fields also.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜