Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Remove trash from xlink table
Message
 
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
01243096
Message ID:
01243105
Views:
23
This message has been marked as the solution to the initial question of the thread.
I like second better because it self-describing. However the first one most likely will be faster in VFP.
The subqueries in second query are called correlated queries because they are referencing fields from the main sql statement. IOW, M2m in subqueries is the table to which DELETE is applied.

>I have a cross-link table for many-to-many named M2m.
>After testing I'd like to remove trash records from it. M2m links records in Dok1 table. Here are two deletes:
>
>1.
>delete M2m from M2m Left Join Dok1 T1 on T1.Pk=M2m.Pk1 ;
>   Left Join Dok1 T2 on T2.Pk=M2m.Pk2 ;
>   Where isnull(T1.Pk) and isnull(T2.Pk)
>
>2.
>delete from M2m where not exists (select Pk from ;
>   Dok1 where Pk=M2m.Pk1) and not exists (Select PK ;
>   from Dok1 where Pk=M2m.Pk2)
>
>Which one of them is better or maybe you suggest your version.
>I also have a question about statement Nr2.
>How do subqueries behaive in such cercumstances? Do they behaive like completely seperate Selects? In my example would the subquery: (Select Pk from Dok1 where Pk=M2m.Pk1) consider M2m for the Delete and M2m for itself as two different tables? So that for every subquery Recno('M2m') will show the same number.
>
>Kamil
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform