Wednesday, 15 January 2014

sql - Mysql Subquery Syntax -



sql - Mysql Subquery Syntax -

i'm wondering why statements select * t appear in mysql subqueries following.

the next deletes oldest 3 rows in table according created_time column.

why right

delete mytable id = ( select * ( select id mytable order created_time asc limit 3')as t)

and not

delete mytable id = (select id mytable order created_time asc limit 3)

?

to me, sec form makes sense. doesn't work , i'd understand why first necessary. specifically, t , as t do?

in many databases, subquery in from clause needs have explicit alias. as optional. typically utilize as columns , leave out tables:

delete mytable id = ( select * ( select id mytable order created_time asc limit 3') t)

why need subquery vagary of mysql. doesn't allow table reference in delete or update appear in subquery clause. oh, allow in subquery-within-a-subquery clause. so, pretty easy work around limitation.

mysql sql syntax subquery

No comments:

Post a Comment