Jump to content

Archived

This topic is now archived and is closed to further replies.

wolf

Subselect in MySql 3.23.46

Recommended Posts

Hi, I\'m having a problem with MySql 3.23.46 :?:

 

I\'m trying to execute a query which has a SUBSELECT.

f.e.:

 

$strSql = \"SELECT *\";

$strSql .= \" FROM Intervenciones I\";

$strSql .= \" WHERE IntDocId=\" . $docId . \" AND NOT EXISTS\";

$strSql .= \" (SELECT ResIntId FROM Respuestas R WHERE\";

$strSql .= \" R.ResResIntId=I.IntId)\";

 

OR

 

$strSql = \"SELECT *\";

$strSql .= \" FROM Intervenciones\";

$strSql .= \" WHERE IntId IN (SELECT ResResIntId FROM Respuestas\";

$strSql .= \" WHERE ResIntId=\" . $intId . \");\";

 

 

I read the MySql 4.1 manual and it says that SUBSELECT\'S are available.

 

I would like to know if my MySQL version is not able to run queries with SUBSELECT\'s.

?>[/code]

Share this post


Link to post
Share on other sites

.. but you can still rewrite the query without a subquery.

 

SELECT Intervenciones.* FROM Intervenciones,Respuestas WHERE Intervenciones.IntId=Respuestas.ResResIntId;

Share this post


Link to post
Share on other sites

This should replace the NOT EXISTS subquery

 

[php:1:08132f0729]<?php

$strSql = \"SELECT *

FROM Intervenciones I LEFT JOIN Respuestas R

ON R.ResResIntId=I.IntId

WHERE I.IntDocId= \'$docId\'

AND R.ResResIntId IS NULL\";

?>[/php:1:08132f0729]

 

hth

Share this post


Link to post
Share on other sites

:D thanks, you confirmed my suspects and investigation.

 

i had already solved my sql queries, i just wanted to confirm that my version is not able to run subselects.

 

I replaced old queries with:

 

$strSql = \"SELECT Intervenciones.*\";

$strSql .= \" FROM Intervenciones\";

$strSql .= \" INNER JOIN Respuestas ON (ResResIntId=IntId)\";

$strSql .= \" AND (ResIntId=\" . $intId . \");\";

 

AND

 

$strSql = \"SELECT Intervenciones.* FROM Intervenciones\";

$strSql .= \" LEFT JOIN\";

$strSql .= \" Respuestas ON Intervenciones.IntId=Respuestas.ResResIntId\";

$strSql .= \" WHERE Respuestas.ResResIntId IS NULL AND IntDocId=\". $docId;

 

 

 

Ahh !!!!! Sorry about my english, it could be bad because i speak spanish and i loose a little practice speaking english.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.