Jump to content


Photo

Subselect in MySql 3.23.46


  • Please log in to reply
4 replies to this topic

#1 wolf

wolf
  • Members
  • Pip
  • Newbie
  • 4 posts

Posted 14 October 2003 - 06:21 PM

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]

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 14 October 2003 - 07:13 PM

AFAIK 4.1 is the first version to support subqueries.
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 Kriek

Kriek
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts
  • LocationFlorida

Posted 14 October 2003 - 07:18 PM

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

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

Jon Kriek ยท PHP Freaks
Sometimes the need to mess with their heads ...
... outweighs the millstone of humiliation.


#4 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 14 October 2003 - 07:33 PM

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
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#5 wolf

wolf
  • Members
  • Pip
  • Newbie
  • 4 posts

Posted 17 October 2003 - 01:27 PM

: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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users