Reputation: 248
I have 2 tables :
tb_doc
:
===========================================
| id | document_title | document_summary |
===========================================
| 1 | a data mining | document_summary1 |
| 2 | B | document_summary2 |
===========================================
tb_wrap
:
============================================
| id | data_url | data_title | doc_url |
===========================================
| 1 |data_url1 | B | doc_url1 |
| 2 |data_url2 | a data mining | doc_url2 |
============================================
I wanna join data from 2 table where document_title
= data_title
(match 2 strings), so I will get the result like :
data_title <href data_url>
doc_url
document_summary
here's the query :
SELECT * from tb_wrap as a
JOIN (
SELECT document_title, document_summary from tb_doc) as b`
ON a.data_title LIKE b.document_title
How to get them? thank you :)
Upvotes: 2
Views: 81
Reputation: 270637
The JOIN
condition should be an =
rather than a LIKE
. I see no need to join against a subquery. This is just a rudimentary INNER JOIN
.
SELECT
tb_wrap.data_url,
tb_wrap.data_title
tb_wrap.doc_url,
tb_doc.document_summary
FROM
tb_doc
INNER JOIN tb_wrap ON tb_doc.document_title = tb_wrap.data_title
Upvotes: 3