0

I'm trying to join two tables based on two values being alike. I have this so far but I'm getting a SQL error as soon as I use the %.

SELECT downloads.d_key, payer_email
FROM    paypal_log
INNER JOIN
        downloads
ON      downloads.d_key LIKE "%" + paypal_log.custom + "%"

The downloads.d_key will be within the paypal_log.custom.

halfer
  • 19,824
  • 17
  • 99
  • 186
Abs
  • 56,052
  • 101
  • 275
  • 409
  • 1
    I don't think `LIKE` was intended to be used in this way. It should be used in the `WHERE` clause. – Bernard Oct 08 '12 at 16:44
  • 1
    This appears to have already been asked here http://stackoverflow.com/questions/1930809/mysql-join-query-using-like – James Piggot Oct 08 '12 at 16:46
  • 1
    is there a way to parse the key out of `paypal_log.custom`? If d_key were 11, it could potentially find other keys of 111, 1111, etc... it's not a good way to join. – msmucker0527 Oct 08 '12 at 16:47
  • @JamesPiggot thanks for that link to the question it worked perfectly. Maybe posting it here again will help? Other options? – Abs Oct 08 '12 at 16:50
  • Possible duplicate of [mysql join query using like?](https://stackoverflow.com/questions/1930809/mysql-join-query-using-like) – Braiam Apr 03 '18 at 15:13

2 Answers2

0

Try

SELECT 'one' + 'two' FROM DUAL

and see what you get. You'll want to use

LIKE concat('%', paypal_log.custom, '%')
dispake
  • 3,259
  • 2
  • 19
  • 22
0

MySQL concatenation operator is ||. You can also use the CONCAT() function:

SELECT downloads.d_key, payer_email
FROM    paypal_log
INNER JOIN
        downloads
ON      downloads.d_key LIKE '%' || paypal_log.custom || '%' ;

As others pointed, you are probably doing something very, very wrong.

ypercubeᵀᴹ
  • 113,259
  • 19
  • 174
  • 235