mysql sub-select work around?

plug-discuss@lists.plug.phoenix.az.us plug-discuss@lists.plug.phoenix.az.us
Wed, 05 Feb 2003 11:58:53 -0700


See section 6.5.3 (near the end)
http://www.mysql.com/documentation/mysql/bychapter/manual_Reference.html#CREATE_TABLE

This syntax is MySQL specific, but all DBs have this feature (all DBs of consequence, anyway).
MS SQL Server uses a Select * Into table_name from .... syntax


On 5 Feb 2003 at 12:44, Mike Starke wrote:

> /_> /_create temporary table tmp_idt
> /_> /_SELECT (idt.unit * idt.price) AS Sub_Total
> /_> /_FROM idt WHERE idt.myid = "1";
> /_> /_
> /_MySQL allows you to create a temp table and populate with the results of a select in one shot.  That's what this 
> /_statement does.  If the 'create temporary table' statement is immediately followed by a select statement, the results 
> /_of the select statement are populated into the the table using the columns names & data types returned from the select 
> /_statement.
> /_
> 
> I had no idea it worked that way (populated if immediately followed by a select..). 
> I looked through the documentation on/at MySQL and could not find this info
> documented anywhere.
> 
> /_As an aside, if the column idt.myid is an int datatype you don't need to quote it.  If it's an integer and you quote 
> /_it, MySQL must do an implicit data type conversion, which may slow things down a bit.  If the myid column is a varchar 
> /_data type then you must quote it.
> /_
> 
> I didn't know that either...........many thanks for the tips today.
> 
> I suspect everything you pointed out above is MySQL specific isn't it. (?)
> I have always made every effort to construct statements plain enough
> as to be ported amongst rdbm's. 
> 
> v/r
> -Mike
> 
> 
> ---------------------------------------------------
> PLUG-discuss mailing list - PLUG-discuss@lists.plug.phoenix.az.us
> To subscribe, unsubscribe, or to change  you mail settings:
> http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss
> 
>