开发者

MYSQL Find data in one table based on one of two fields in another table

Complete noob question, so apologies for that.

I have two tables, a members table with a开发者_JAVA技巧n 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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜