Search code examples
mysqlsqlsql-like

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


How can I combine those two queries into one?

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

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

2) This finds all japanese words with the sign for 'dog' (犬) in it:

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

3) I am having trouble combining those two into one, because this doesn't work?!

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

Solution

  • Parenthesises are important, therefore, try this :

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

    It might have been good to tell us what error you received, though.