SELECT * FROM tbl WHERE clm LIKE CONCAT('%',<其他 sql 查询 limit 1>,'%') - 如何?

发布于 2024-09-28 11:06:41 字数 461 浏览 3 评论 0原文

如何将这两个查询合并为一个?

1)这会找到日语中的狗(犬)符号:

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

2)这会找到所有带有“狗”(犬)符号的日语单词:

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

3)我无法将这两个组合成一个,因为这不会工作?!

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

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,'%'
);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

伴我心暖 2024-10-05 11:06:41

括号很重要,因此,尝试这样做:

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

不过,告诉我们您收到的错误可能会更好。

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.

孤凫 2024-10-05 11:06:41

使用:

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

我不建议使用 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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文