sql - In MySQL, what does this simple nested SELECT clause mean exactly? -


here example thread:

select (   select distinct salary employee order salary desc limit 1 offset 1 )as second; 

the select(...) second looks confusing me because i've never seen query-set instead of column names can used argument of select..

does have ideas how understand nested select clause this? there tutorials feature?

that's subquery in select list of query.

to there, let's @ other examples

select t.id      , 'bar' foo    mytable  ...  limit ... 

'bar' string literal gets returned in every row (in column named foo) in resultset query.

also, mysql allows run query without clause

select 'fee' fum 

we can put subquery in select list of query. example:

select t.id      , (select r.id resorts r order r.id asc limit 1) id   mytable  ...  limit ... 

the query pattern asked select statement without clause

and expression being returned result subquery.

for example:

 select e.salary     employee e   group e.salary   order e.salary desc   limit 4,1 

if query runs, return 1 column, , return either 1 or 0 rows. (no more one.) satisfies requirements subquery used in select list of query.

select ( subquery ) alias 

with that, outer query executes. there's no clause, mysql returns 1 row. resultset going consist of 1 column, name of "alias".

for each row returned outer query, mysql execute subquery in select list. if subquery returns row, value of expression in select list of subquery assigned "alias" column of resultset. if execution of subquery doesn't return row, mysql assigns null "alias" column.


Comments

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -