[英]How to get all results from a query except just one
I have a sqlite database with a few tables the relevant ones for this question being tweet_data and sentiment_t.我有一个带有几个表的 sqlite 数据库,与这个问题相关的表是 tweet_data 和 Sentiment_t。
tweet_data contains a lot of data about a singular tweet including the user_id from the sender and the tweet id itself. tweet_data 包含有关单个推文的大量数据,包括来自发件人的 user_id 和推文 ID 本身。 Sentiment_t contains all the tweet_ids and a sentiment associated with the tweet_text. Sentiment_t 包含所有 tweet_id 和与 tweet_text 关联的情绪。
I want to get all of the sentiments associated with a single user.我想获得与单个用户相关的所有情绪。 To do this I wrote the following query:为此,我编写了以下查询:
''' '''
SELECT sentiment_c
FROM sentiment_t
WHERE sentiment_t.id = (SELECT id
FROM tweet_data
WHERE user_id = 1662186764);
''' '''
I know for sure that there are 15 tweets associated with user_id 1662186764, this query however only returns the first sentiment.我确定有 15 条推文与 user_id 1662186764 相关联,但是这个查询只返回第一个情绪。
How do I fix this?我该如何解决?
With what you've described I'm not sure how you get any result.根据您的描述,我不确定您如何获得任何结果。 So let's start.所以让我们开始吧。
You have multiple tweets in tweet_data
meaning that select id from tweet_data where user_id= 1662186764
will return more than one row.您在tweet_data
中有多条推文,这意味着select id from tweet_data where user_id= 1662186764
将返回多行。 You cannot compare multiple rows with =
.您不能用=
比较多行。 You need to use the IN
operator.您需要使用IN
运算符。
So correct query should look something like this:所以正确的查询应该是这样的:
SELECT sentiment_c
FROM sentiment_t
WHERE sentiment_t.id IN (SELECT id
FROM tweet_data
WHERE user_id = 1662186764);
(switched operator =
with IN
) (切换运算符=
带有IN
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.