cassandra - 如何执行表查询? [英] cassandra - how to perform table query?
本文介绍了cassandra - 如何执行表查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试使用两个表执行查询:
I am trying to perform a query using 2 tables:
CREATE TABLE users(
id_ UUID PRIMARY KEY,
username text,
email text,
);
CREATE TABLE users_by_email(
id UUID,
email text PRIMARY KEY
)
在这种情况下,如何通过电子邮件执行查询?
In this cas, how to perform a query by email?
推荐答案
我假设您还希望在查询中返回 username
。您不能在Cassandra中JOIN表。为此,您必须将该列添加到您的 users_by_email
表中:
I am assuming that you also want username
returned in the query. You cannot JOIN tables in Cassandra. So to do that, you will have to add that column to your users_by_email
table:
CREATE TABLE users_by_email(
id UUID,
email text PRIMARY KEY,
username text,
);
然后,只需通过电子邮件地址查询该表。
Then, simply query that table by email address.
> SELECT id, email, username FROM users_by_email WHERE email='mreynolds@serenity.com';
id | email | username
--------------------------------------+------------------------+----------
d8e57eb4-c837-4bd7-9fd7-855497861faf | mreynolds@serenity.com | Mal
(1 rows)
这篇关于cassandra - 如何执行表查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文