dsdtumf776629385 2012-06-21 10:56
浏览 167

在PHP中将两个查询合并为一个

I need to make the following two queries into one but can't, When I try to test it it doesnt run at all and I'm not sure why. If anyone could help I would be thankful. This is my first query -

$exportArray[] = $row['reviewId'];
$row_num++;

$sql = <<<SQL
SELECT * FROM review WHERE (reviewForum = "$reviewForum") 

And this is my second -

$sql = "SELECT * FROM mom WHERE ( reviewId = " . $row['reviewId'] . " )";

I tried UNION but doesn't work either. The common fields between the two tables is reviewId. I am querying two tables and the first query above works but when I try to include the second one I can't get it to work. Thanks if anyone can help me, it's probably something small but I've been looking at it for a while now and it's very annoying at this stage.

  • 写回答

2条回答 默认 最新

  • douyan6871 2012-06-21 11:10
    关注

    You may try this:

    SELECT a.*, b.*
    FROM review a
    JOIN mom b 
    ON a.reviewId=b.reviewId
    WHERE a.reviewForum ='$reviewForum'
    

    I assume, reviewId is in both tables

    评论

报告相同问题?

悬赏问题

  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable