wolf Posted October 14, 2003 Share Posted October 14, 2003 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] Quote Link to comment https://forums.phpfreaks.com/topic/1166-subselect-in-mysql-32346/ Share on other sites More sharing options...
Barand Posted October 14, 2003 Share Posted October 14, 2003 AFAIK 4.1 is the first version to support subqueries. Quote Link to comment https://forums.phpfreaks.com/topic/1166-subselect-in-mysql-32346/#findComment-3920 Share on other sites More sharing options...
Kriek Posted October 14, 2003 Share Posted October 14, 2003 .. but you can still rewrite the query without a subquery. SELECT Intervenciones.* FROM Intervenciones,Respuestas WHERE Intervenciones.IntId=Respuestas.ResResIntId; Quote Link to comment https://forums.phpfreaks.com/topic/1166-subselect-in-mysql-32346/#findComment-3921 Share on other sites More sharing options...
Barand Posted October 14, 2003 Share Posted October 14, 2003 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 Quote Link to comment https://forums.phpfreaks.com/topic/1166-subselect-in-mysql-32346/#findComment-3922 Share on other sites More sharing options...
wolf Posted October 17, 2003 Author Share Posted October 17, 2003 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. Quote Link to comment https://forums.phpfreaks.com/topic/1166-subselect-in-mysql-32346/#findComment-3948 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.