La mejor solución con LIMIT subconsulta MySQL

i want to create Stored PROCEDURE with multi statement, and it not working , and Google the problem and found that mysql dose not support Subquery statement "MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'"

My statement like this:

CREATE PROCEDURE `DBName`.`proc_Name`()
    SELECT FROM table1 WHERE ORDER BY table1_Colom LIMIT 100;
    UPDATE table2 SET table2_colom1 = 1 WHERE ID IN  (SELECT ID FROM table2 ORDER BY table2_colom1 LIMIT 100);

preguntado el 09 de enero de 11 a las 07:01

This seems like a strange thing to want to do. How are you choosing which 100 to update? Are you updating the same 100 each time? Can you explain your actual use case? -

i know it looks strange, but in first statement i get 100 record(order by colom); Then i want to update there status -

2 Respuestas

        table2, (SELECT ID FROM table2 ORDER BY table2_colom1 LIMIT 100) AS temp_table
        table2_colom1 = 1 
        table2.ID =;

Respondido el 09 de enero de 11 a las 22:01

I have a sneaking (and optimistic) feeling that the issue here is just SELECTing on the same table you perform update on. The ORDER BY is dependent on the exact ID you are changing. I think alias miht help, so give different alias and try:

UPDATE table2 T2 SET T2.table2_colom1 = 1 WHERE T2.ID IN  
     (SELECT T2A.ID FROM table2 T2A ORDER BY T2A.table2_colom1 LIMIT 100); 

I don't have the means to test now =(
¡Déjame saber si funciona!

Respondido el 09 de enero de 11 a las 11:01

thanks for response BUT "MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery" MySQL Documentation - Hiyasat

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.