Note that there are some explanatory texts on larger screens.

plurals
  1. POmysql set to null or 0 if right join returns no rows
    primarykey
    data
    text
    <p>I have the following query which is returning no rows. however if this occurs i would like to set the values to 0 or null. how do i do this?</p> <pre><code>UPDATE `hdb`.`projects` RIGHT JOIN ( SELECT jobs.PROJID, round(SUM(jobs.value),2) AS SumOfJobValues, round(Sum(jobs.Earned),2) AS SumOfEarnedValues FROM jobs WHERE projects.PROJID = 1312184 GROUP BY jobs.PROJID ) as temp ON projects.PROJID = temp.PROJID SET projects.VALUE = round(SumOfJobValues,2), projects.WIP = round(SumOfEarnedValues,2) </code></pre> <p>I rewrote my query for using left join and it works in mysql. however when i run this using php Yii framework i does not work.</p> <pre><code>UPDATE `hdb`.`projects` left JOIN ( SELECT jobs.PROJID, round(SUM(jobs.value),2) AS SumOfJobValues, round(Sum(jobs.Earned),2) AS SumOfEarnedValues FROM jobs GROUP BY jobs.PROJID ) as temp ON projects.PROJID = temp.PROJID SET projects.VALUE = round(SumOfJobValues,2), projects.WIP = round(SumOfEarnedValues,2) WHERE projects.PROJID = 1312184 </code></pre> <p>same query running on php Yii</p> <pre><code>$sql = "UPDATE `hdb`.`projects` LEFT JOIN ( SELECT jobs.PROJID, round(SUM(jobs.value),2) AS SumOfJobValues, round(Sum(jobs.Earned),2) AS SumOfEarnedValues FROM jobs WHERE jobs.PROJID = :pid GROUP BY jobs.PROJID as temp ON projects.PROJID = temp.PROJID SET projects.VALUE = round(SumOfJobValues,2), projects.WIP = round(SumOfEarnedValues,2) WHERE projects.PROJID = :pid"; $command=$connection-&gt;createCommand($sql); $command-&gt;bindValue(":pid",$model-&gt;PROJID,PDO::PARAM_INT); $command-&gt;execute(); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload