0

i have three table like:

table 1:

|A|B|C|D|

table 2:

|A|E|F|G|

table 3:

|G|H|

what i need in result is:

|A|B|C|D|H|

initially i check only the first two table taking, from table1 all the rows and from table2 the column G in that rows that satisfy the condition table1.A = table2.A

something like:

SELECT `table1`.*,`table2`.`G` FROM `table1` INNER JOIN `table2` WHERE `table1`.`A`=`table2`.`A`

My problem now is to take column H from table3 using like key value G that satisfy old condition. i hope my question is a little bit clear.. can someone help me? thanks!

Jayyrus
  • 12,961
  • 41
  • 132
  • 214

4 Answers4

2
SELECT `table1`.*,`table2`.`G`,`table3`.`H`
FROM `table1` 
INNER JOIN `table2` ON `table1`.`A`=`table2`.`A`
INNER JOIN `table3` ON `table2`.`G`=`table3`.`G`
Giuseppe
  • 597
  • 7
  • 26
  • 1
    as the fieldname is same in both tables, you can use ``USIGNG (`A`)`` insted of ``ON `table1`.`A`=`table2`.`A` `` – Puggan Se Jul 18 '12 at 12:46
0

This is the most simple way to do it with implicit inner joins.

SELECT T1.A, T1.B, T1.C, T1.D, T3.H 
FROM `table1` T1, `table2` T2, `table3` T3 
WHERE T1.A = T2.A AND T2.G = T3.G
Josh Brown
  • 935
  • 1
  • 11
  • 21
0

Try this:

SELECT
  `t1`.*,
  `t2`.`G`,
  `t3`.`H`
FROM
  `table1` AS `t1`
INNER JOIN
  `table2` AS `t2`
  ON `t1`.`id` = `t2`.`t1_id`
INNER JOIN
  `table3` AS `t3`
  ON `t1`.`id` = `t2`.`t2_id` (or join with table 2 I dont know)
WHERE
  `t1`.`A`=`t2`.`A`
Ruben
  • 8,956
  • 14
  • 63
  • 102
0

select table1.A,table1.B,table1.C,table1.D,table3.H from table1,table2,table3 where table1.A=table2.A AND table2.G=table3.G

Amrita
  • 581
  • 4
  • 6