19 Jul 2012 17:55
[U2] MySQL query qestion....
George Gallen <ggallen <at> wyanokegroup.com>
2012-07-19 15:55:47 GMT
2012-07-19 15:55:47 GMT
This is specific to MySQL, but could apply to any SQL DB. Is there a way to put the results of one query to be used by another, without having that second query run on each Iteration of the sub query? Example: SELECT * FROM TABLE WHERE LAST_UPDATE > (SELECT UPDATE_PROCEDURE()); The function UPDATE_PROCEDURE() returns a timestamp, and then updates itself with a new timestamp. My workaround is: SELECT * FROM TABLE WHERE LAST_UPDATE > (SELECT GET_PROCEDURE()); SELECT UPDATE_PROCEDURE(); Here the GET_PROCEDURE() only retrieves a value, and doesn't update it. BUT...if there were half a million records in the TABLE, I'd prefer not to run the GET procedure half a million times To retrieve the same result which could add significant processing time (this would be run for each of the tables I'm mirroring on UV from MySQL . George _______________________________________________ U2-Users mailing list U2-Users <at> listserver.u2ug.org http://listserver.u2ug.org/mailman/listinfo/u2-users(Continue reading)
Cheers,
Wol
On 19/07/12 17:29, Brian Leach wrote:
> George
>
> It depends on the db type. In SQL Server, for example, you would create a
> stored procedure that would capture the subquery result to a local variable
> and use that.
>
> e.g.
>
> DECLARE <at> lastUpdate DATETIME;
> SELECT <at> lastUpdate = some_expression ;
> select * from table where last_update > <at> lastUpdate
>
> But I don't know with mySQL - it's a bit short on intellect - but I see it
> has a SELECT .. INTO format for populating a variable. Might be worth a
RSS Feed