Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Some Help with Select statement
Message
From
22/09/2003 05:32:41
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00830332
Message ID:
00831002
Views:
27
>>>>>Hi Kevin,
>>>>>
>>>>>>... the Times AND the Sunday Times and NO other papers.
>>>>>
>>>>>
>>>>> WHERE INLIST(ItemId, ID_SUNDAYTIMES, ID_TIMES); && <-- this is OR
>>>>>   ...
>>>>>
>>>>>
>>>>>Fabio
>>>>
>>>>So it is :-)
>>>>
>>>>
WHERE ItemId = ID_SUNDAYTIMES OR ItemId = ID_TIMES
>>>>
>>>>Thanks for the correction.
>>>>
>>>>Kev
>>>Kev,
>>>Unfortunately that still does and OR not and AND across multiple records which is what I need.
>>
>>Oops, I'm not with it today.
>>
>>Do you have to achieve this in 1 select?
>>
>>Kev
>
>Ideally yes.

Hang on a minute, try this:

For Sunday Times and The Times:
SELECT CustId ;
  FROM Sub;
 WHERE ItemId = 1;
   AND CustId NOT IN (SELECT CustId FROM Sub WHERE ItemId != 1 AND ItemId != 2);
 UNION;
SELECT CustId;
  FROM Sub;
 WHERE ItemId = 2;
   AND CustId NOT IN (SELECT CustId FROM Sub WHERE ItemId !=1 AND ItemId !=2) 
Then, for The Times, Sunday Times and the Daily Telegraph, just to prove concept.
SELECT CustId ;
  FROM Sub;
 WHERE ItemId = 1;
   AND CustId NOT IN (SELECT CustId FROM Sub WHERE ItemId != 1 AND ItemId != 2 AND ItemId !=3);
 UNION;
SELECT CustId;
  FROM Sub;
 WHERE ItemId = 2;
   AND CustId NOT IN (SELECT CustId FROM Sub WHERE ItemId !=1 AND ItemId !=2 AND ItemId !=3);
 UNION;
SELECT CustId;
  FROM Sub;
 WHERE ItemId = 3;
   AND CustId NOT IN (SELECT CustId FROM Sub WHERE ItemId !=1 AND ItemId !=2 AND ItemId !=3)
Does that work?

Kev
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform