Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL syntax needed
Message
From
21/11/2008 13:14:16
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9 SP2
Miscellaneous
Thread ID:
01363325
Message ID:
01363538
Views:
20
>>>>>>Thank you William.
>>>>>>
>>>>>BTW, there are other ways to get the same information, but this one is the simplest to remember.
>>>>
>>>>"Simplest" is very subjective and depends upon how one "grew up" with SQL. I think the pre-VFP9 version
>>>>SELECT * FROM Table2 WHERE date IN (SELECT MAX(Date) AS Date FROM Table1)
is simpler to remember. I will accept that the more "modern" code is "better" and may run faster, etc. but simpler, like beauty, is in the eye of the beholder.
>>>
>>>The code above is not correct.
>>>
>>>When I was coming home I was thinking I should write a FAQ on this topic since it's a commonly asked question. I thought it through, but I don't think if I can find the time to actually do this.
>>
>>"The code above is not correct."
>>
>>How so? I get the same results as Borrislav using the sample data provided. Could you show me conditions where the results will differ?
>
>I meant here, that for date fields you usually don't use IN syntax, you use DATE = (...) Other than that, it's fine.

Actually, the field type doesn't matter, and in this case IN and = have the same effect. The difference is that when you use =, you're restricted to a subquery that returns a single result and you're comparing against that result. With IN, your subquery can return multiple results, and you'll get any record that matches any of them. Because the subquery in this case always returns a single result, the two are functionally equivalent.

Tamar
Previous
Reply
Map
View

Click here to load this message in the networking platform