结合两个查询Mysql

时间:2016-04-27 18:56:11

标签: mysql

我正在尝试合并两个查询。

False & True

$query_1 = mysql_query("SELECT * FROM `table1_results` WHERE id=".$_GET['id']);
while($table1_results = mysql_fetch_assoc($query_1)){
    $total[] = $table1_results;
}
  一切都保持不变,只是我想结合两种不同的方式   表

     

table2_results

     

     一个查询中的

table2_results

我咨询了很多例子,但没有得到理想的结果,请举例说明问题的正确解决方案 谢谢

2 个答案:

答案 0 :(得分:2)

您应该使用内部联接

  SELECT * FROM `table1_results`  as a
  Inner join `table2_results` as b on a.id = b.id 
  WHERE a.id=".$_GET['id']

答案 1 :(得分:0)

如何选择多个表?

Select * from `table1_results` as t1, `table2_results` as t2
where t1.id = $_GET['id'] OR t2.id = $_GET['id']