Anda di halaman 1dari 4

2/14/2017 OracleSQL&PL/SQL:DifferencebetweenNested&CorrelatedSubqueries

34 More NextBlog CreateBlog SignIn

OracleSQL&PL/SQL
Oracle,SQLServer,SQL,PL/SQL,SQLInterviewQuestions,SQL/PLSQLInterviewQuestions,SQL
Joins,MultipleChoiceQuestionsonSQLandSQLUnion

RSS
34
Feed
OracleSQL&PL/SQL
IfyoulikereadingthisOracleSQL/PLSQLblog,pleasehelp
DifferencebetweenNested& increasetheblogs'visibilitybyclickingonthe'g+1'button.

CorrelatedSubqueries
OracleSQL OraclePL/SQL
Therearetwomaintypesofsubqueriesnestedand
correlated.Subqueriesarenested,whenthesubqueryis SQLIntroduction PL/SQLIntroduction
executedfirst,anditsresultsareinsertedintoWhereclauseof
SQLSyntax PL/SQLProcedures
themainquery.Correlatedsubqueriesaretheoppositecase,
wherethemainqueryisexecutedfirstandthesubqueryis SQLSelect PL/SQLFunctions
executedforeveryrowreturnedbythemainquery.[Via:SqlBy SQLInsert PL/SQLCollections
Leon] SQLUpdate PL/SQLRecords
SQLDelete PL/SQLTableBased
NestedSubqueries Records
Asubqueryisnestedwhenyouarehavingasubqueryinthe SQLJoins
SQLExamplesofJoins PL/SQLProgrammer
whereorhavingclauseofanothersubquery.
DefinedRecords
SQLExplicitvs.Implicit
Gettheresultofallthestudentswhoareenrolledinthesame Joins PL/SQLCursorBased
Records
courseasthestudentwithROLLNO12. SQLGroupBy
PL/SQLTables
Select* SQLGroupByExamples
PL/SQLVarrays
Fromresult SQLHaving
PL/SQLNestedTables
whererollnoin(selectrollno SQLIN
fromstudent PL/SQLLoops
SQLNULLs
wherecourseid=(selectcourseid PL/SQLTriggers
FunctionalDependencies
fromstudent PL/SQLCursors
whererollno=12)); Normalization
PL/SQLImplicitCursors
ACIDProperties
Theinnermostsubquerywillbeexecutedfirstandthenbasedon PL/SQLExplicitCursors
SQLSubQueries
itsresultthenextsubquerywillbeexecutedandbasedonthat PL/SQLREFCursors
resulttheouterquerywillbeexecuted.Thelevelstowhichyou SQLQueriesWith
Examples PL/SQLCursorForLoop
candothenestingisimplementationdependent.
SQLViews PL/SQLCursorswith
Parameters
CorrelatedSubquery Insert,Update,Delete
Views PL/SQLWhereCurrentOf
andForUpdate
ACorrelatedSubqueryisonethatisexecutedaftertheouter SQLJoinViews
queryisexecuted.Socorrelatedsubqueriestakeanapproach ExamplesofPL/SQL
SQLInlineViews Cursors
oppositetothatofnormalsubqueries.Thecorrelatedsubquery
SQLNthHighestSalary PL/SQLExceptions
executionisasfollows:
SQLSecondHighestSalary PL/SQLInterview
SQLDifferenceTruncate Questions
Theouterqueryreceivesarow. /Delete SQLPL/SQLSitemap
Foreachcandidaterowoftheouterquery,the
SQLDifferenceTruncate
subquery(thecorrelatedsubquery)isexecuted /Drop
once.
SQLDifferenceHAVING/ SQLServer
Theresultsofthecorrelatedsubqueryareusedto
WHERE MultipleChoice
determinewhetherthecandidaterowshouldbepart
SQLDifferenceCAST/ Questions
oftheresultset.
CONVERT
Theprocessisrepeatedforallrows.
SQLMultipleChoice
SQLDifferenceNOTIN/
Questions
NOTEXIST
CorrelatedSubqueriesdifferfromthenormalsubqueriesinthat SQLDifferenceIN/
thenestedSELECTstatementreferesbacktothetableinthe EXISTS
firstSELECTstatement. SQLDifferenceUNION/
UNIONALL

http://sqlplsql.blogspot.in/2011/09/differencenestedcorrelatedsubquery.html 1/4
2/14/2017 OracleSQL&PL/SQL:DifferencebetweenNested&CorrelatedSubqueries
Tofindoutthenamesofallthestudentswhoappearedinmore SQLDifferenceNested/
thanthreepapersoftheiroptedcourse,theSQLwillbe CorrelatedSubquery
SQLREPLACE
Selectname
fromstudentA SQLTOP
Where3<(selectcount(*) SQLLIKE
fromresultb SQLSELECTINTO
whereb.rollno=a.rollno);
SQLCREATETABLE

Inotherwords,acorrelatedsubqueryisonewhosevalue SQLCREATETABLE
dependsuponsomevariablethatreceivesitsvalueinsome (MoreExamples)
outerquery.Anoncorrelatedsubqueryassaidbeforeis SQLALTERTABLE
evalutedinabottomtoupmanner,i.e.theinnermostqueryis SQLDifferenceviews/
evaluatedfirst.Butacorrelatedsubqueryisresolvedinatop Materializedviews
tobottomfashion.Thetopmostqueryisanalyzedandbasedon SQLCount
thatresultthenextqueryisinitiated.Suchasubqueryhastobe
SQLUpdate
evaluatedrepeatedly,onceforeachvalueofthevariablein
question,insteadofonceandforall. SQLClustered/Non
ClusteredIndexes
SQLDeleteDuplicate
Records
CorrelatedsubqueriesimprovetheSQLperformance
SQLDifference
when: Unique/PrimaryKey

Onlyafewrowsareretrievedthroughtheouterqueryand SQLGETDATE()
especiallywhenouterquery'sWHEREclause,whichlimitsthe SQLDATEDIFF()
numberofrowsretrieved,canuseanindex. SQLDATEADD()
SQLDATEPART()
SQLConvert()
Thecorrelatedinnerqueriesareperformedthroughanindex
SQLSUM()
scan.Thisisveryimportantifthetableortablesagainstwhich
theinnerqueryisperformedislargeandtheindexscanhasto SQLAVG()
retrieveonlyasmallpercentageofitsrows. SQLMIN()
SQLMAX()
SQLInsertIntoSelect
Inothercasesviewsandjoinsarelikelytobemoreefficient. SQLInsertMultiple
Buttheonlysurewaytosaywhichmethodisefficientisto ValuesInTable
analyzetheexecutionplanofthequeryandtheresourcesused SQLReferentialIntegrity
byit.[via:IntroductiontoDatabaseManagementSystemsBy
SQLNotNullConstraint
IsrdGroup]
SQLUniqueConstraint
SQLPrimaryKey
Constraint
SQLForeignKey
Constraint
NewerPost Home OlderPost SQLDefaultConstraint
SQLCheckConstraint
SQLROLLUP
SQLCUBE
SQLSTUFF()
SQLCount_Big
SQLBinary_Checksum
SQLChecksum_AGG
SQLIndexInclude
SQLCoveredQuery
SQLIdentity
SQLsp_columns
SQLDiffLocal/Global
TemporaryTables
SQLStoredProcedure
SQLsp_who
SQLSession
SQLDynamicSQL
SQLSQLServer
ExecutionPlan
SQLsp_executesql
SQLDifference
Execute/Execute()
SQLCaseExpression

http://sqlplsql.blogspot.in/2011/09/differencenestedcorrelatedsubquery.html 2/4
2/14/2017 OracleSQL&PL/SQL:DifferencebetweenNested&CorrelatedSubqueries
SQLXMLVariable
Example
SQLPivot
SQLMerge
ExampleofSQLMerge
ExampleofMergeOutput
Clause
SQLCompute/Compute
by
SQLDiff
SCOPE_IDENTITY/
IDENT_CURRENT/
@@IDENTITY
SQLCoalesce
SQLImportDatainto
SQLServerTable
SQLDeleteDuplicate
RecordsinSQLServerTable
SQLCheckIfaColumn
ExistsinSQLServerTable
SQL
Has_perms_by_name
SQLDifferencebetween
Logins/Users
SQLDiffbetweenTable
Variable/TempTable
SQLSQLServer2012
features
SQLSERVERPROPERTY
SQLFindPrimaryKey/
ForeignKeyinTable
SQLSequence
SQLColumnstore
Indexes
SQLDifferencePrimary/
CandidateKey
SQLThrowSQLServer
2012
SQLDifferenceGUID/
INT
SQLServer2012
Enhancements
SQLDiffbetweenCross
Join/FullOuterJoin
SQLNTILE()
SQLObjectDependencies
SQLEmailReminderon
UpdatingTable
SQLObjectDefinition
SQLServerReport
Builder3
SQLServerUserDefined
Roles
SQLServerFiletables
SQLServerContained
Databases
SQLServerUpdatefrom
Select
SQLServerXMLMethods
SQLServerAdda
ColumntoTable
SQLServerInsert
MultipleRows
SQLServerAddIdentity
ColumntoTable
SQLServerIndexes
SQLServerDiff
Functions/StoredProcedures

http://sqlplsql.blogspot.in/2011/09/differencenestedcorrelatedsubquery.html 3/4
2/14/2017 OracleSQL&PL/SQL:DifferencebetweenNested&CorrelatedSubqueries
SQLComparison
OperatorsAny/All
SQLDifferencePrimary/
ForeignKey
SQLDifferenceReplace/
Stuff
SQLROW_NUMBER()
SQLIntersect
SQLServerLocal
Variables
SQLServerUpdatewith
Join
SQLServerDifference
Merge/HashJoin
SQLServerDifference
Update/ExclusiveLock
SQLServerDifference
Instance/Database
SQLServerDifference
Datetime2/Datetime
SQLServerDifference
Disable/DropIndexes
SQLServerDifference
Decimal/Float
SQLServerDATEDIFF
withExamples
SQLServerDifference
Raiserror/Throw
SQLServerCheckIf
ColumnExistsinTable
SQLServerQueryExcel
UsingLinkedServer
SQLServerWaitFor
SQLServerDifference
Rank,Dense_Rank&
Row_Number
SQLServerPATINDEX
Examples
SQLInterviewQuestions
SQLJoinInterview
Questions

PoweredbyBlogger.

http://sqlplsql.blogspot.in/2011/09/differencenestedcorrelatedsubquery.html 4/4

Anda mungkin juga menyukai