SELECT * FROM tbl WHERE clm LIKE CONCAT ('%', <other sql query LIMIT 1>, '%') - HOW?

How to combine these two queries into one?

1) This finds the Japanese sign for the dog (犬):

SELECT japanese 
  FROM edict 
 WHERE english LIKE 'dog' 
 LIMIT 1;

2) This finds all Japanese words with the sign “dog” (犬) in it:

SELECT japanese 
  FROM edict 
 WHERE japanese LIKE '%犬%';

3) I had problems combining the two into one, because it doesn’t work ?!

SELECT japanese 
FROM edict 
WHERE japanese
LIKE CONCAT('%',
    SELECT japanese FROM edict WHERE english LIKE 'dog' LIMIT 1,'%'
);
+5
source share
2 answers

So, it is important to know that this is happening:

SELECT japanese
FROM edict
WHERE japanese LIKE CONCAT('%', 
                           (SELECT japanese FROM edict WHERE english LIKE 'dog' LIMIT 1), 
                           '%');

It might have been nice to tell us what error you got.

+15
source

Using:

SELECT a.japanese 
  FROM EDICT a
  JOIN EDICT b ON b.japanese = a.japanese
 WHERE b.english LIKE 'dog'

I do not recommend using LIMIT, but if you really need it, use:

SELECT a.japanese 
  FROM EDICT a
  JOIN (SELECT t.japanese
          FROM EDICT t
         WHERE t.english LIKE 'dog'
         LIMIT 1) b ON b.japanese = a.japanese
+4
source

All Articles