[mysql] PB requete avec des select imbriqués

PB requete avec des select imbriqués [mysql] - SQL/NoSQL - Programmation

Marsh Posté le 21-05-2003 à 14:59:11    

voici mon code

Code :
  1. $sql = "delete from POST where POST.POST_TOPIC_CODE in (";
  2. $sql = $sql . " select TOPIC_CODE from TOPIC where TOPIC.TOPIC_THEME_CODE in (";
  3. $sql = $sql . " select THEME_CODE from THEME where THEME.THEME_SECTION_CODE = " . $section_code . " ) );";
  4. echo $sql ."<br><br>";
  5. mysql_query($sql,$link) or die("<br>[ INVALID QUERY ] : " . mysql_error());


 
Resultat:

Citation :


delete from POST where POST.POST_TOPIC_CODE in ( select TOPIC_CODE from TOPIC where TOPIC.TOPIC_THEME_CODE in ( select THEME_CODE from THEME where THEME.THEME_SECTION_CODE = 1 ) );
 
 
[ INVALID QUERY ] : You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'select TOPIC_CODE from TOPIC where TOPIC.TOPIC_THEME_CODE in (


 
 
Par contre quand j'utilise des requetes successives ca marche. Donc pas de problèmes de sql en théorie:

Code :
  1. $toto = "";
  2. $tata = "";
  3. $sql = "select THEME_CODE from THEME where THEME.THEME_SECTION_CODE = " . $section_code . ";";
  4. $rs1 = mysql_query($sql,$link) or die("<br>[ INVALID QUERY 1] : " . mysql_error());
  5. while ($row1 = mysql_fetch_array($rs1,MYSQL_ASSOC))
  6. {
  7.  $toto = $toto . "," . $row1["THEME_CODE"];
  8. }
  9. $sql = "select TOPIC_CODE from TOPIC where TOPIC.TOPIC_THEME_CODE in (0 " . $toto . " );";
  10. $rs1 = mysql_query($sql,$link) or die("<br>[ INVALID QUERY 2] : " . mysql_error());
  11. while ($row1 = mysql_fetch_array($rs1,MYSQL_ASSOC))
  12. {
  13.  $tata = $tata . "," . $row1["TOPIC_CODE"];
  14. }
  15. $sql = "delete from POST where POST.POST_TOPIC_CODE in (0 " . $tata . " );";
  16. $row1 = mysql_query($sql,$link) or die("<br>[ INVALID QUERY 3] : " . mysql_error());


 
EDIT: ah oui j'oubliais, j'ai bien la version 4.0.13 de MySQL.
REEDIT: en fait non je ne suis pas en 4.0.13 :(
sous phpinfo(), ca m'affiche Client API version 3.23.49.
Pourtant j'ai bien installé MySQL 4.0.13 puis PHP 4.3.1 (la version installer pour win32). Et le numéro de version reste le même...

Reply

Marsh Posté le 21-05-2003 à 14:59:11   

Reply

Marsh Posté le 21-05-2003 à 15:04:06    

il me semble que les requêtes imbriquées c'est en version > 4.1 pour MySQl [:psywalk]


---------------
from here and there -- \o__________________________________ -- la révolution de la terre, en silence
Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed