小新 的 BLOG
            
            -=Oracle、MS SQLServer还有MySQL,当然也少不了应用程序数据库操作=-

Correlated Subqueries

Correlated Subqueries
Morning a colleague asked me a SQL statement how to update rows in a table base on other from another table.So easy.
My answer is "update emp_salary es set es.subsidy1 = (select worktime * 10 from employee emp where emp.empid = es.empid and emp.worktime > 10)".
What Is a Subquery?
A subquery is a SELECT statement embedded in a clause of another SQL statement.
For Example "select * from employee emp where empid in (select emp from salary where tax > 1000)" . in this statement "select emp from salary where tax > 1000" is the subquery embedded in the main statement .
Correlated subqueries are useful whenever a subquery must return a different result for each candidate row.[from Extended Data Retrieval with SQL by Oracle]
With Exists operator you can return boolean value;

some point:
1、Subquery(inner query) excutes once before the main query(outer query)(once of every row of the outer query).
2、The result of the subquery is used by the main query.
标签集:TAGS:
回复Comments()点击Count()

回复Comments

{commenttime}{commentauthor}

{CommentUrl}
{commentcontent}
  用户登录
用户名
密 码
选 项:
 
  我的日历
  分类日志
  访问计数
  获取 RSS
bluelover 最新的 20 条日志
  最新评论
  友情链接
  联系我
                  GMail:bluelover@gmail.com
MSN:xini_huang@hotmail.com
QQ:85364603
Modified by blueloverPowered by 5DBlog.com