需要 mysql 查询帮助
我是 mysql 新手,所以请你帮助我。 我有 2 个表“单词”和“文本”
单词具有列:
- 单词
- 同义词
文本具有列:
- 文本
- 单词
- article_id
我需要获取唯一的words.word 和最大的唯一text.atricle_id 字段。同一个article_id可以有不同的单词。例如
words
word synonyms
-----------------------
car auto, vehicle
water syn1, syn2
bus syn1, syn2
text
text word article_id
---------------------------------------
any text car 1
any_text water 1
any_text water 2
any_text car 2
any_text bus 1
any_text bus 3
I need to get the result:
car | 2
water | 1
bus | 3
我有一个查询,但它返回非唯一的article_id
SELECT words.word, text.article_id
FROM `words` , `text`
WHERE text.word = words.word
GROUP BY words.word
ORDER BY text.article_id DESC
I'm new to mysql so please can you help me.
I have 2 tables "words" and "text"
words has columns:
- word
- synonyms
text has columns:
- text
- word
- article_id
I need to get unique words.word, and biggest unique text.atricle_id fields. The same article_id can have different words. for example
words
word synonyms
-----------------------
car auto, vehicle
water syn1, syn2
bus syn1, syn2
text
text word article_id
---------------------------------------
any text car 1
any_text water 1
any_text water 2
any_text car 2
any_text bus 1
any_text bus 3
I need to get the result:
car | 2
water | 1
bus | 3
I have a query but it return non unique article_id
SELECT words.word, text.article_id
FROM `words` , `text`
WHERE text.word = words.word
GROUP BY words.word
ORDER BY text.article_id DESC
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
此查询将得到您想要的结果:
结果:
注释 1:如您在问题中所述,水的 Maximum_article_id = 2 而不是 = 1。
注意 2:
ORDER BY text.article_id DESC
不会按照您在问题中陈述的顺序给出结果。This query will get the result you want:
Result:
Note 1: water has biggest_article_id = 2 and not = 1 as you state in the question.
Note 2:
ORDER BY text.article_id DESC
won't give you the result in the order you state in the question.也许这会做到这一点:
Maybe this will do it: