Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Very embarassing - Access query
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9
OS:
Windows XP SP2
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01063741
Message ID:
01063802
Views:
9
OK, if insist
Maybe I am missing something, but I don't see any reason for second select, why not just:
select * from Visits;
    INTO CURSOR test
BROW
Or if you want to join doctors table (if you select some fields from Doctors table), use LEFT join not INNER.
select *, Doctros.SomeField;
    FROM Visits;
    LEFT JOIN Doctors ON Visits.DoctorField = Doctors.MatchingField
    INTO CURSOR test
BROW
>>>>I didn''t see the reason of JOIN and with second select. Try this:
>>>>
>>>>select Patient_name, Visit_date, MAX(other_field), COUNT(*) AS Cnt from Visits;
>>>>       FROM VISITS
>>>>       GROUP BY VISITS.patient_name, VISITS.visit_date
>>>>       HAVING Cnt>1
>>>>
>>>
>>>That's wrong. We need information about each visit. This query would not give it. The other query works great, but I'm sure we can write another version of it either using EXISTS keyword or some JOIN commands. In fact I saw Sergey and Fabio writing these kinds of selects, but I don't remember right now.
>>>
>>>BTW, my colleague said, that he got it now. E.g. looks like my slopish explanation was enough for him.
>>
>>But with that select you'll get only this opatients that have at least 2 visits at a same date. Try:
>>
>>CREATE CURSOR Visits (Patient_name C(50), Visit_Date D, OtherField C(20))
>>INSERT INTO Visits VALUES ("Boris", DATE(),"Something")
>>INSERT INTO Visits VALUES ("Boris", DATE(),"Something else")
>>INSERT INTO Visits VALUES ("Boris", DATE()+1,"Other")
>>
>>
>>select * from Visits;
>>where patient_name + DTOS(Visit_Date) in;
>>  (SELECT VISITS.patient_name+DTOS(VISITS.visit_date);
>>          FROM VISITS GROUP BY VISITS.patient_name, VISITS.visit_date;
>>          HAVING count(VISITS.visit_date)>1);
>>INTO CURSOR test
>>BROW
>>** Two records only first two
>>
>
>Without even trying it it seems like in the inner select we need to group only by patient.
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform