繁体   English   中英

MySQL:匹配2个具有多个值的表中的记录

[英]MySQL: Matching records from 2 tables with multiple values

我有2张桌子:

表格1

id | title     | author       | url
1  | the-test  | james-brown  | www.thetest.com
2  | the-house | clancy-brown | www.thehouse.com
3  | the-desk  | leanne-brown | www.thedesk.com
4  | the-head  | julie-brown  | www.thehead.com

表2

id | title     | author       | url**
1  | the-mouse | john-blue    | www.themouse.com
2  | the-house | clancy-brown | www.thehouse.com
3  | the-cups  | carrie-blue  | www.thecups.com
4  | the-head  | clancy-brown | www.thehead.com

我需要的结果只显示其中两个 titleauthor的比赛,即

2  | the-house | clancy-brown | www.thehouse.com

我已经试过了:

select *
from table1
inner join table2 on (table1.title=table2.title) AND (table1.author=table2.author)

但是它永远运行(实际表中实际上有数十万行)。

请注意,这很好用:

select *
from table1
inner join table2 on (table1.title=table2.title)

我只是无法让它匹配两个表。 有更聪明的方法吗?

感谢您提前提供的所有帮助。

我认为您的SQL很好,您只需要在作者上索引table1和table2。 添加这些索引,JOIN将足够快。 您还遇到一个问题,您在示例数据中称呼列author ,并在第一个查询中name它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM