使用联接的Club 2查询

时间:2015-03-04 11:33:11

标签: php mysql join

假设我有两个查询,如下所示

select a.item1,b.item2 from tablename a,tablename b;

store a.item1 as $value1;

select c.item3 from tablename c where c.item4=$value1;

我需要将这两个查询分为一个查询,并使用Joins

P.S: in PHP.

任何帮助表示感谢。

3 个答案:

答案 0 :(得分:1)

如果您在三个表中具有相同的字段,则可以通过以下查询

执行此操作
select a.item1 as value1,b.item2,c.item3 from tablename a inner join tablename b on a.id=b.table1_id inner join tablename c on c.item4=value1;

的问候,
雷卡

答案 1 :(得分:0)

如果你的表名是“a”,“b”和“c”,那么你可以这样加入:

SELECT a.item1, b.item2, c.item3 FROM a, b
  INNER JOIN c ON a.item1 = c.item4;

不需要PHP代码,只需要SQL。

答案 2 :(得分:0)

试试这个..

select a.item1,b.item2,c.item3 from a join b on a.id = b.table_a.id
join c on a.item1 = c.item4
相关问题