SQL (this AND that), OR (that AND theOther)

Roger Eller roger.e.eller at sealedair.com
Tue Oct 8 21:29:19 EDT 2013


I didn't give you a good example.  I didn't mean to have Ford and Chevy
listed twice.  The car is unique.

In hindsight, it would have been clearer to have car AND uniqueOwnerID as
the example field names.

~Roger
On Oct 8, 2013 8:39 PM, "Roger Eller" <roger.e.eller at sealedair.com> wrote:

> John - Essentially, the queries are like this:  If there are 13 pair of
> 'AND' criteria, I would expect 13 rows of data to be returned.  The user
> can exist multiple times, but each car is unique.  In fact, car could be a
> unique number like a VIN.
>
> My goal is to submit only 1 query, built from a list of (user AND car),
> and get back 1 row for each pair.  I'm not locked in to using OR if there
> is a better way.
>
> SELECT * FROM myDatabase WHERE
>  ((user = 'Joe') AND (car = 'Ford')) OR
>  ((user = 'Joe') AND (car = 'Chevy')) OR
>  ((user = 'John') AND (car = 'Ford')) OR
>  ((user = 'John') AND (car = 'Chevy')) OR
>  ((user = 'John') AND (car = 'Kia')) OR
>  ((user = 'John') AND (car = 'Smart')) OR
>  ((user = 'John') AND (car = 'Volkswagon')) OR
>  ((user = 'John') AND (car = 'Honda')) OR
>  ((user = 'John') AND (car = 'Hyundai')) OR
>  ((user = 'John') AND (car = 'Dodge')) OR
>  ((user = 'John') AND (car = 'Saturn')) OR
>  ((user = 'Jim') AND (car = 'BMW')) OR
>  ((user = 'Jim') AND (car = 'Jaguar'))
> ORDER BY car DESC
>
> ~Roger
>
>
> On Tue, Oct 8, 2013 at 5:34 PM, John Craig <john at splash21.com> wrote:
>
>> For clarity, can you post the entire query?
>>
>>
>>
>> On 08/10/2013 21:52, Roger Eller wrote:
>>
>>>   Having some SQL query troubles...  I need to get results from a long
>>> list
>>> in a single query, BUT there are pairs of fields that must match.  Every
>>> pair is a unique pair, aka no duplicates.  If my list contains 50 pair
>>> that
>>> are unique, I may only get 30 returned rows, but I need all 50.
>>>
>>> This is what I've tried, but SQL strips away my outer parens, making my
>>> AND
>>> less binding for the pair.
>>>
>>> WHERE
>>>        ((user = 'Joe') AND (car = 'Ford')) OR
>>>        ((user = 'John') AND (car = 'Chevy')) OR
>>>        ((user = 'Jim') AND (car = 'Kia')) OR
>>>        ((user = 'Jim') AND (car = 'Smart'))
>>>
>>> ~Roger
>>> ______________________________**_________________
>>> use-livecode mailing list
>>> use-livecode at lists.runrev.com
>>> Please visit this url to subscribe, unsubscribe and manage your
>>> subscription preferences:
>>> http://lists.runrev.com/**mailman/listinfo/use-livecode<http://lists.runrev.com/mailman/listinfo/use-livecode>
>>>
>>>
>>
>> ______________________________**_________________
>> use-livecode mailing list
>> use-livecode at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:
>> http://lists.runrev.com/**mailman/listinfo/use-livecode<http://lists.runrev.com/mailman/listinfo/use-livecode>
>>
>
>



More information about the use-livecode mailing list