0

I have a query that looks at partial matches within two mysql tables to make a join:

SELECT table1.column, table2.column FROM table1, table2 WHERE table1.val LIKE table2.val

This works fine as a join, but... some of the values in table2 are actually substrings of the values in table one—specifically they're urls. So, table1.val might equal http://google.com while table2.val = google.com.

How do I use the '%' operator around the table2 val to make this comparison.

Thanks in advance!

0

2 Answers 2

4

Like this:

... WHERE table1.val LIKE CONCAT('%', table2.val, '%')

Note that this will not perform as well as table1.val = table2.val, as it must now search all rows in table2.

Sign up to request clarification or add additional context in comments.

Comments

0

Q: How do I use the '%' operator around the table2 val to make this comparison.

A: You don't :)

You can specify a column by name (e.g. "mycolumn"), by fully qualified name (e.g. "mytable.myname") or by ordinal (e.g. "1").

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.