On Tuesday 05 February 2002 9:59 am, Barry J. Wiegan wrote:
> Hi,
>
> I'm trying to build a query to solve a fairly simple problem.
> I have two tables (A and B) linked by a common ID. I want to
> locate a specific record in A that is linked to two or more
> records in B based on second field in B matching certain criteria.
> I've tried every type of inner, outer, left, and right join
> to accomplish this, but can't come up with anything that works.
>
> EG:  Select * from A inner join B on A.ID=B.ID where B.Val='25'
>      and B.Val='35';
>
> This will rturn zero matching records since B.Val can't
> equal 25 and 35 at the same time.

SELECT * FROM A inner join B on A.ID = B.ID inner join B AS C on A.ID = C.ID 
where B.Val = '25' and C.val = '35'.

Or something similar.  I can't be bothered to open my SQL reference at the 
moment.  :)

(For the sake of completeness, it is worth realising that you would _often_ 
need to ensure that the row in B and C are not the same row... not necessary 
here, though as you know they aren't as B.val and C.val are different).

---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to