Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Find where more than 1 record exists
Message
From
02/05/2003 09:04:27
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
01/05/2003 15:51:10
Jay Johengen
Altamahaw-Ossipee, North Carolina, United States
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00783789
Message ID:
00784064
Views:
16
>>>I can easily do this with 2 statements, but what would be the SQL logic to Select only records where there were more than one meeting the criteria:
>>>
>>>
>>>MyField1     MyField2
>>>========     ========
>>>John         12345
>>>Jim          98765
>>>John         12345
>>>
>>>
>>>I only want this as a result:
>>>
>>>
>>>John         12345
>>>
>>>
>>>I only want 1 record with John and do not want Jim at all.
>>>
>>>Thanks, Renoir
>>
>>Try something like this;
>>
>>
>>SELECT MyField1, MyField2, COUNT(MyField1) AS HowMany ;
>>  FROM MyTable GROUP BY MyField1, MyField2
>>  HAVING HowMany > 1 INTO CURSOR MyResult
>>
>
>Jim,
>
>What if I really want both records for John, but not the one for Jim? This wasn't what I thought I needed before, now it is.
>
>Renoir

PMFJI,
Select * from myTable a ;
  where exists ;
  ( select * from myTable b ;
	where a.Myfield1 = b.Myfield1 and a.Myfield2 = b.myField2 ;
	having cnt(*) > 1 ;
	group by b.Myfield1, b.myField2)
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Reply
Map
View

Click here to load this message in the networking platform