If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Join Problem?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-21-04, 09:11
andris2000 andris2000 is offline
Registered User
 
Join Date: Feb 2004
Posts: 4
Join Problem?

Hello all
I have following two tables:

table_X
+-------+
| a_id | b_id |
+-------+
| 1 | 2 |
| 1 | 3 |
| 2 | 2 |
| 3 | 3 |
| 4 | 1 |
| 4 | 2 |
| 4 | 3 |

table_Z
+-----------------+
| b_id | system |
+----------------+
| 1 | 0 |
| 2 | 1 |
| 3 | 0 |
| 4 | 1 |

Now I need to have the result which would list all table_X a_id's that contain table+Z b_id's that have system flag=1.

How can I achieve this ?
Reply With Quote
  #2 (permalink)  
Old 02-23-04, 02:51
reneeb reneeb is offline
Registered User
 
Join Date: Jan 2004
Location: Germany
Posts: 167
Is b_id in table_X the foreign key??

Code:
SELECT a_id FROM table_X INNER JOIN table_Z ON table_X.b_id = table_Z.b_id WHERE system = 1;
__________________
board.perl-community.de - The German Perl-Community
Reply With Quote
  #3 (permalink)  
Old 02-25-04, 11:55
andris2000 andris2000 is offline
Registered User
 
Join Date: Feb 2004
Posts: 4
Another join

Thanks, that's ok but now I need to have the result which would list all table_X a_id's that contain table+Z b_id's with all system flag=0.
I mean all b_id's should be not system. If even one of the b_id's for specific a_id is system, record is not returned.

Is it possible with mysql?
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On