Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL Statement
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01179984
Message ID:
01179995
Views:
14
If I'm reading the sample data correctly, there should be no selections from your sample data. I added one row and changed the official
ALLEN, JUDY C.	500	Rickey Peete	7/11/2002
I don't have VFP 9 available and couldn't figure out a way to do it in one query with VFP 8. In two steps, however,
SELECT DISTINCT name,official FROM contrib INTO CURSOR xxx WHERE official in (c1,c2)

SELECT name,amount,official,date FROM contrib;
 WHERE name IN (SELECT name FROM xxx;
                 GROUP BY name;
                 HAVING count(*) > 1)
got me the expected results.

I haven't had the chance to work with nested selects yet but someting on the order of
SELECT name,amount,official,date FROM contrib;
 WHERE name IN (SELECT name FROM (SELECT DISTINCT name,official FROM contrib);
                 GROUP BY name HAVING COUNT(*) > 1)
might work.

At least I hope so.

..........Rich

>>Hi John,
>>
>>Yes, I realized that you get all contributions for people who made donations to those 2 officials. You've to add the same where clause to the main select
>>
>>SELECT name,amount,official,date FROM cmoney ;
>> WHERE name IN (SELECT name FROM cmoney ;
>>              WHERE official = ?Official1 or official = ?Official2 );
>>             GROUP BY 1 HAVING COUNT(*) > 1) ;
>>     AND official = ?Official1 or official = ?Official2
>>
>>
>>
>It's still not happening. I'm getting all results from both officials.
>
>name amount official date
>ABC-ED PAC 5000 Mark Luttrell 3/24/2006
>AC WHARTON FOR 500 Mark Luttrell 5/21/2004
>ADAMS, J. KEVIN 500 Mark Luttrell 3/20/2006
>ADSTAFF LLC 1000 Mark Luttrell 5/28/2003
>AFSCME 250 Rickey Peete
>AFSCME 250 Rickey Peete
>AFSCME 300 Rickey Peete
>ALLEN, JUDY C. 500 Mark Luttrell 7/11/2002
>ALLEN, MARILYN 500 Mark Luttrell 1/12/2006
>ALLEN, SCHELIA 500 Mark Luttrell 5/11/2004
>ALLEN, WILLIAM 500 Mark Luttrell 3/17/2005
>ALMOND, BARBAR 1000 Mark Luttrell 7/23/2002
>
>
>The results should only show if the leftmost column contributed to both Luttrell and Peete. I'm getting all.
>
>John
>
>
>>>
>>>Here is my select statement and it is giving me more elected officials than it should.
>>>
>>>
>>>SELECT name,amount,official,date FROM cmoney WHERE name IN (SELECT name FROM cmoney ;
>>>WHERE (official = ?Official1 or official = ?Official2 );
>>>GROUP BY 1 HAVING COUNT(*) > 1)
>>>
>>>I only want records which include (name) contributor who gave to both officials.
>>>
>>>john doe,1/1/99,1000.00,A.Politician
>>>john doe,12/4/98,500.00,B.Politician
>>>
>>>Above is a simplification of how the result set should look.
>>>
>>>
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform