Re: [[PHP-ES] subselect.]

From: Date: Thu, 28 Sep 2000 23:28:55 +0000
Subject: Re: [[PHP-ES] subselect.]
Groups: php.general.es 
Request: Send a blank email to general-es+get-2036@lists.php.net to get a copy of this message
Hola * Bueno lista este problema se presenta en versiones de mysql menores a la 3.22 en esta dan esta solucion: 5.4.1 Sub-selects The following will not yet work in MySQL: SELECT * FROM table1 WHERE id IN (SELECT id FROM table2); SELECT * FROM table1 WHERE id NOT IN (SELECT id FROM table2); However, in many cases you can rewrite the query without a sub select: SELECT table1.* FROM table1,table2 WHERE table1.id=table2.id; SELECT table1.* FROM table1 LEFT JOIN table2 ON table1.id=table2.id where table2.id IS NULL For more complicated subqueries you can often create temporary tables to hold the subquery. In some cases, however this option will not work. The most frequently encountered of these cases arises with DELETE statements, for which standard SQL does not support joins (except in sub-selects). For this situation there are two options available until subqueries are supported by MySQL. The first option is to use a procedural programming language (such as Perl or PHP) to submit a SELECT query to obtain the primary keys for the records to be deleted, and then use these values to construct the DELETE statement (DELETE FROM ... WHERE ... IN (key1, key2, ...)). The second option is to use interactive SQL to contruct a set of DELETE statements automatically, using the MySQL extension CONCAT() (in lieu of the standard || operator). For example: SELECT CONCAT('DELETE FROM tab1 WHERE pkid = ', tab1.pkid, ';') FROM tab1, tab2 WHERE tab1.col1 = tab2.col2; You can place this query in a script file and redirect input from it to the mysql command-line interpreter, piping its output back to a second instance of the interpreter: prompt> mysql --skip-column-names mydb < myscript.sql | mysql mydb MySQL only supports INSERT ... SELECT ... and REPLACE ... SELECT ... Independent sub-selects will be probably be available in 3.24.0. You can now use the function IN() in other contexts, however. ellos prometen que para versiones ulteriores daran soporte para subselect, y si se ven apurados pueden pasarse a postgres hay son tal cual en SQL standar espero que te sirva de algo. Santa Marta Magdalena Colombia Sur America Usuario Linux # ____________________________________________________________________ Get free email and a permanent address at http://www.netaddress.com/?N=1

« previous php.general.es (#2036) next »