SELECT * FROM tbl WHERE clm LIKE CONCAT('%',,'%') - HOW?

前端 未结 2 597
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-04 20:37

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         


        
相关标签:
2条回答
  • 2021-01-04 21:25

    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.

    0 讨论(0)
  • 2021-01-04 21:27

    Use:

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

    I don't recommend the use of LIMIT, but if you really need it for this, 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
    
    0 讨论(0)
提交回复
热议问题