Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Should SQL statement be one or more
Message
From
04/05/2005 14:59:53
 
 
To
04/05/2005 14:32:19
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 6 SP5
OS:
Windows 2000 SP4
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01010960
Message ID:
01010976
Views:
24
This message has been marked as a message which has helped to the initial question of the thread.
>I have a select statement as such:
>
>SELECT CLIENTNM.DISTRICT, ADDRES.STATE, ALIASES.NAME_ALIAS, ;
>  CLNTREF.REF_COD, CR_HIST.VDATE, CUSTOMER.CR_RATING, PRODUCTS.DEDNT ;
> FROM CLIENTNM, ADDRES, ALIASES, CLNTREF, CR_HIST, CUSTOMER, PRODUCTS, ;
>    CONTACT ;
>  WHERE CLIENTNM.IDCLIENT = ADDRES.IDCLIENT AND ;
>    ADDRES.ADDRESS_TY = "MN" AND ;
>    CLIENTNM.IDCLIENT = ALIASES.IDCLIENT AND ;
>    ALIASES.ALIAS_TYPE = "MAIN" AND ;
>    CLIENTNM.IDCLIENT = CUSTOMER.IDCLIENT AND ;
>    CLIENTNM.IDCLIENT = PRODUCTS.IDCLIENT AND ;
>    CLIENTNM.IDCLIENT = CR_HIST.IDCLIENT AND ;
>    CLIENTNM.IDCLIENT = CONTACT.IDCLIENT AND ;
>    CLIENTNM.IDCLIENT = CLNTREF.IDCLIENT AND ;
>    CONTACT.CONTACT_ID = CLNTREF.CONTACT_ID ;
>  ORDER BY 1 DESC ;
>  INTO TABLE CLNTSHAWNA.DBF
>
>but the result table brings up multiple instances of any client where there are 2 or more records in cr_hist and/or clntref. I want the latest date for the cr_hist.vdate for each client and just one record from the clntref for the client.
>
>Would it be easier to do several select statements to get this infor, or can someone show me the way to do it for one select statement.
>
>Thanks in Advance.
>Beth

Beth,

I'd suggest JOIN syntax for all the table relations and use of the MAX() function for Cr_Hist.vDate. While its not required until VFP8, you should group by all the other fields in the result set.

You may also want to experiment with breaking it up into multiple queries to see which is the fastest.

Good luck,
Jim
Previous
Reply
Map
View

Click here to load this message in the networking platform