gpt4 book ai didi

mysql - 获取所有term等于Mysql查询的条目

转载 作者:行者123 更新时间:2023-11-29 15:33:05 26 4
gpt4 key购买 nike

我有 2 张 table

新闻

+---------+---------------+---------------+--------------+--------+
| news_id | title | short | body | etc... |
+---------+---------------+---------------+--------------+--------+
| 881971 | Article Title | Article short | Article Body | |
| 881972 | Article Title | Article short | Article Body | |
| 881973 | Article Title | Article short | Article Body | |
+---------+---------------+---------------+--------------+--------+

术语

+-----+--------------+
| tid | news_term_id |
+-----+--------------+
| 14 | 881971 |
| 2 | 881972 |
| 2 | 881973 |
+-----+--------------+

我需要从表News中选择所有内容,其中Term中的tid等于2(例如)尝试这样:

SELECT *
FROM news, term
WHERE news.news_id = term.tid
GROUP BY term.tid

但这不是我需要的。就像带有类别的博客文章一样,需要选择类别 id 2 的所有文章

最佳答案

这是您要找的吗?

select n.*, t.*
from news n
inner join term t
on n.news_id = t.news_term_id
and t.tid = 2

关于mysql - 获取所有term等于Mysql查询的条目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58530856/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com