MySQL SELECT * FROM tbl WHERE clm LIKE CONCAT('%',<other sql query LIMIT 1>,'%') - 如何?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4005251/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SELECT * FROM tbl WHERE clm LIKE CONCAT('%',<other sql query LIMIT 1>,'%') - HOW?
提问by ajo
How can I combine those two queries into one?
如何将这两个查询合二为一?
1) This finds the japanese sign for dog (Ȯ):
1) 这找到了 dog (Ȯ) 的日语符号:
SELECT japanese
FROM edict
WHERE english LIKE 'dog'
LIMIT 1;
2) This finds all japanese words with the sign for 'dog' (Ȯ) in it:
2) 这会找到所有带有 'dog' (Ȯ) 符号的日语单词:
SELECT japanese
FROM edict
WHERE japanese LIKE '%Ȯ%';
3) I am having trouble combining those two into one, because this doesn't work?!
3)我无法将这两者合二为一,因为这不起作用?!
SELECT japanese
FROM edict
WHERE japanese
LIKE CONCAT('%',
SELECT japanese FROM edict WHERE english LIKE 'dog' LIMIT 1,'%'
);
回答by Vincent Savard
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.
不过,最好告诉我们您收到了什么错误。
回答by OMG Ponies
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:
我不推荐使用 LIMIT,但如果你真的需要它,请使用:
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

