1

The following code work's properly.

SELECT Message
FROM SystemEventsR
WHERE Message
LIKE CONCAT('%',(SELECT username FROM users LIMIT 1),'%')

My question though, is most of the time i need to return more than one row.

I omit the LIMIT which results to an 'Error Code 1242'

Why is this?

I need all messages which contain at least one username

I also used a JOIN but to no avail

SELECT Message
FROM SystemEventsR
JOIN users ON Message LIKE CONCAT('%',(SELECT username FROM users),'%')

I would like something like the following, but the number of rows in users table is not constant

SELECT Message
FROM SystemEventsR
WHERE 
Message LIKE CONCAT('%',(SELECT username FROM users LIMIT 1,1),'%') OR
Message LIKE CONCAT('%',(SELECT username FROM users LIMIT 2,1),'%') OR
Message LIKE CONCAT('%',(SELECT username FROM users LIMIT 3,1),'%')
Cœur
  • 37,241
  • 25
  • 195
  • 267

2 Answers2

5

Why not simply;

SELECT Message 
FROM SystemEventsR s
JOIN users u
  ON s.Message LIKE CONCAT('%',u.username,'%')

An SQLfiddle to test with.

Joachim Isaksson
  • 176,943
  • 25
  • 281
  • 294
1

Can you try this:

SELECT Message
FROM SystemEventsR
WHERE Message
RLIKE (SELECT GROUP_CONCAT(username SEPARATOR '|') FROM users)

Check the manual regarding RLIKE .

georgepsarakis
  • 1,927
  • 3
  • 20
  • 24