Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Which SQL Select would be faster?
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9 SP1
Miscellaneous
Thread ID:
01095983
Message ID:
01095995
Views:
13
Thank you for your input. I did try a few queries but it is hard to tell which is faster with just a few hundred records in my test data. The subquery I had worked too, however. Yours probably work too. Now I am wondering between 3 cases (instead of two). Thanks for your help <g>.

>First, the proof is in the pudding (pardon the metaphor). Try both and see which is better, however, your second query should be as follows:
>
>select * FROM PARENT WHERE PK_fld IN (SELECT distinct PK_FLD FROM CHILD WHERE
>(&cChildFilter))
>
>
>Good Luck.
>
>
>>I need to select records from a Parent Table filtering on fields
>>in the Child Table. But I only need to select (show) fields from the Parent table.
>>
>>I am deciding which approach would be faster:
>>
>>
>>*-- Approach 1. Selecting records from both tables with JOIN and
>>*-- then grouping them
>>select MAX(PARENT.FLD1), MAX(PARENT.FLD2) from PARENT
>>  left join CHILD where (&cChildFilter) GROUP BY PARENT.PK_FLD
>>
>>
>>vs
>>
>>
>>*-- Approach 2. Selecting record from Parent table with subquery
>>*-- from Child table.
>>select P.* FROM PARENT P WHERE EXIST (SELECT * FROM CHILD C WHERE
>>(&cChildFilter) AND C.PK_FLD = P.PK_FLD)
>>
>>
>>I would appreciate any suggestions/input.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Reply
Map
View

Click here to load this message in the networking platform