Mysql Joins

Discussion in 'PHP' started by MichaelLewis, May 15, 2008.

  1. #1
    Can we join more than 2 tables or must we use another method to get data from 3 tables?

    T1: Name, StateID, TaskID

    T2: StateID, StateName

    T3: TaskID, TaskDesc

    I want to select & print: Name, StateName, TaskDesc

    Thanks,
    Michael
     
    MichaelLewis, May 15, 2008 IP
  2. gauravgrt

    gauravgrt Peon

    Messages:
    2,035
    Likes Received:
    129
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Yes you can do it.

    select t1.name, t2.stakename, t3.taskdesc from (t1 inner join t2 on t1.stateid=t1.stateid) inner join t3 on t1.taskid=t3.taskid
     
    gauravgrt, May 15, 2008 IP
  3. Altari

    Altari Peon

    Messages:
    188
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    SELECT a.`name`, b.`statename`, c.`taskdesc`
    FROM `t1` a, `t2` b, `t3` c
    WHERE [your conditions]
     
    Altari, May 15, 2008 IP