tags:

views:

26

answers:

2

Complete noob question, so apologies for that.

I have two tables, a members table with an email address and telephone number in it and a second table that will have email addresses and telephone numbers in it with many instances of the members' telephone number or email address. I want to query the second table and list all results corresponding to each member's email address or telephone number.

Thanks very much

A: 

Here's a rough query based on the info you supplied:

select members_table.*, joined_tables.* 
from members_table, 
((select * from second_table 
 join members_table 
    on members_table.email_address = second_table.email_address)
union /* or intersect if you don't want dupes */
(select * from second_table 
 join members_table 
    on members_table.telephone_number = second_table.telephone_number)
) joined_tables;

At least it should give you an idea on how to go about it.

slashmais
thank you! really appreciate it
Textus
A: 

I`m not sure if I understood your problem, but try this:

SELECT m.* FROM member_table m INNER JOIN second_table s ON m.email = s.email

This will give you all rows of member_table that have rows in second_table, assuming that email columns uniquely . But I strongly suggest, that you find or invent another column that references the second table. Email addresses and telephone numbers tend to change over time.

tombom
thanks v much for the advice
Textus