Hard to understand your example:  b_field2 is not part of your table b table 
structure; your example table b rows are missing either their ID field or the 
non-existent b_field2 and the explanation as to why table A rows A1 and A3 would 
qualify is not clear when the values 1 and 3 are not related to fields.

Original Message:
-----------------
From: Steen Rabol [EMAIL PROTECTED]
Date: Thu, 31 Jan 2002 21:24:43 +0100
To: [EMAIL PROTECTED]
Subject: Is this possible in one SQL statement


Is this possible in a single select statement ?

 table A id (Unique), a_field1,a_field2,a_field3
 table B id(NOT unique), b_field1

 Id in table B is a ref to id in table A

 Now i would like to select all the id's from table A which have records i
 table B where b_field1 is 1 and b_field2 is 2

 example:

 Table a record: 1, "text","text","text"  - A1
 Table a record: 2, "text","text","text" - A2
 Table a record: 3, "text","text","text" - A3

 Table b record 1, 1
 Table b record 2, 2
 Table b record 1, 3
 Table b record 2, 1
 Table b record 1, 4
 Table b record 3, 1
 Table b record 3, 3

 the condition is then value 1 and 3 and the record I want is A1 and A3 due
to the fact that a recorc exists in table B with a value of on and one
record with the value of 3

Is it clean ;-))


I know that it can be done with a nested loops, but is it possible in one
statement sql query ?

Thanks in advance

Steen



---------------------------------------------------------------------
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

--------------------------------------------------------------------
mail2web - Check your email from the web at
http://mail2web.com/ .


---------------------------------------------------------------------
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