الانتقال إلى المحتوى

متى يتم استخدام Nested Subquery و Correlated


omar-alreyati

Recommended Posts

الاخوة الاعزاء :

سؤالي في subquery : متى يتم استخدام Nested Subquery
ومتي يتم استخدام Correlated Subquery

وما الفرق بينهما ، وما الفائدة من استخدام Correlated Subquery ولماذا لايتم استخدام Nested Subquery دائماً ..........؟؟؟؟؟؟؟؟؟


راجياً منكم الرد لأهمية الموضوع للجميع .

تم تعديل عنوان الموضوع من قبل المشرف , راجع شروط الكتابه

فى المنتدى تفاديا حذف موضوعك مره اخره

رابط هذا التعليق
شارك

If you do a search for "correlated subquery" on the Web, you will find several sites suggesting that:

A correlated subquery is a subquery that is evaluated once for each row of the outer query.

It may indeed be convenient to imagine a correlated subquery as being "evaluated" or "executed" once for each row of the outer query; do not, however, be misled into thinking that the database optimizer actually executes it in that fashion, because this will lead you to believe that it's not very efficient, when in fact most optimizers will process a correlated subquery very efficiently, as a join.

Okay, with that out of the way, what's the difference between an ordinary subquery and a correlated subquery? The correlated subquery makes an actual reference, using a correlation variable, to the outer query. For example, here's a query with two subqueries:

select studentname
, studentmark
, ( select avg(studentmark)
from students
where class = t1.class ) as classaverage
, ( select avg(studentmark)
from students ) as schoolaverage
from students t1
In the above example, t1 is the correlation variable that lets the correlated subquery refer to the table in the outer query. For each student, two averages are calculated: the average mark of all students in the same class, and the overall average of all students in all classes.

Here's another example of a correlated subquery, this time in the WHERE clause:

select category
, articletitle
, articlepubdate
from articles zz
where articlepubdate
= ( select max(articlepubdate)
from articles
where category = zz.category )
In this example, only the most recent article in each category is selected

see the original site Here

رابط هذا التعليق
شارك

السلام عليكم
اسف للتاخير فى الرد و ذلك بسبب الانشغال
النوع الاول و هو ال nested query
بمعنى مبسط هو لما يكون فى ال where جملة select

اما النوع التانى Correlated
وهو وجود استعلام فى جملة ال where و يكون بيستخدم عمود من الاستعلام اللى فى ال outer statment
مثال ذلك

select category
, articletitle
, articlepubdate
from articles zz
where articlepubdate
= ( select max(articlepubdate)
from articles
where category = zz.category )

رابط هذا التعليق
شارك

انضم إلى المناقشة

يمكنك المشاركة الآن والتسجيل لاحقاً. إذا كان لديك حساب, سجل دخولك الآن لتقوم بالمشاركة من خلال حسابك.

زائر
أضف رد على هذا الموضوع...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   تمت استعادة المحتوى السابق الخاص بك.   مسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

جاري التحميل
×
×
  • أضف...

برجاء الإنتباه

بإستخدامك للموقع فأنت تتعهد بالموافقة على هذه البنود: سياسة الخصوصية