Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL: Distinct, Group By, or Exists?
Message
From
04/06/2003 18:21:32
 
 
To
04/06/2003 17:44:38
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00796420
Message ID:
00796440
Views:
11
hello Chris

haven't heard from you in a while. how are you doing?

I do not have Vfp8, i still work with 6 :-(. but i tested once the perfomance on a complex sql with 1 and more sub-sql within an sql against a table with about 60000 records. let me tell you - that realy slowed down things.

now, i am not an expert in rushmore technowledgy and sql commands, but it seem to me, on large tables, that unless you have your indexes just right, for such an sql command, i would go with the following:
SELE * DISTINCT ;
   FROM temp1, temp2 ;
   WHERE ;
      temp1.KeyFld = temp2.KeyFld .AND. ;
      temp2.Condition = .T.
again, as i mentioned before, i am not that knowledgeble in that area, but i would think that a single sql statement should be faster then a complex one. maybe someone can explain the workings there a bit better on either of the solutions?!


>Not having strong experience with SQL, I need a little help to get the right result set for a new view.
>
>TableA: PrimaryKey(I), DataItem(C 20)
> 1, Apples
> 2, Oranges
> 3, Pears
> 4, Bananas
>TableB: ForeignKey(I), Condition(L)
> 1, .T.
> 1, .T.
> 2, .F.
> 4, .T.
> 4, .T.
> 4, .F.
>
>Result: PrimaryKey(I), DataItem(C 20)
> 1, Apples
> 4, Bananas
>(One result from Table A only if there's a True Condition in table B.)
>
>Normally, I'd try to join the tables and use DISTINCT PrimaryKey, or GROUP BY PrimaryKey. Shouldn't those give the same result? Which is better? Does VFP8's change to GROUP BY syntax change this? Would an EXISTS clause (which I've never used before) work?
Previous
Reply
Map
View

Click here to load this message in the networking platform