对多个表运行查询

发布于 2024-10-16 06:30:42 字数 719 浏览 2 评论 0原文

我正在尝试在两个表中进行查询:

  • SIMPLE_PERSON 有 3 个字段(姓名、网格和社会保障卡)
  • INDIVIDUAL_AGGREGATE 有 4 个字段:grid(PK)、类型( D(Driver) 或 C(client)), code, simple_person(simple_person 的外键))

当我注册某人时,我必须将它们保存在 SIMPLE_PERSON 上并设置聚合类型他们是(司机或客户)。并且不能有两个相同的社会保障卡号码。

使用 AJAX,我抛出一个检查器,如果 SSC 已注册,它会返回一个警报框,但我的 SQL 查询不起作用。我需要进行查询,如果社会保障卡已注册,该查询将返回给我。我正在尝试使用 EXISTS,但没有取得太大成功:

SELECT simple_person.name 
  FROM simple_person 
 WHERE SSC = 'SSC_NUMBER' 
   AND EXISTS (SELECT individual_aggregate.code FROM individual_aggregate
                WHERE code = 'xx' 
                  AND individual_aggregate.type = 'D');

有人可以帮助我使这个查询工作吗?

I'm trying to make a query in two tables:

  • SIMPLE_PERSON with 3 fields (name, grid and Social Security Card)
  • INDIVIDUAL_AGGREGATE with 4 fields: grid(PK), type( D(Driver) or C(client)), code, simple_person(foreign key of simple_person))

When I register some person, I have to save they on the SIMPLE_PERSON and set the type of aggregate that they are ( Driver or Client). And cannot have two equal social security card numbers.

With AJAX, I throw a checker that returns an alert box if the SSC is registered, but my SQL query doesn't work. I need to making a query that returns to me if a Social Security Card is already registered. I'm trying to use EXISTS, but I haven't had much success:

SELECT simple_person.name 
  FROM simple_person 
 WHERE SSC = 'SSC_NUMBER' 
   AND EXISTS (SELECT individual_aggregate.code FROM individual_aggregate
                WHERE code = 'xx' 
                  AND individual_aggregate.type = 'D');

Somebody can help me to make this query work?

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

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

发布评论

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

评论(3

以酷 2024-10-23 06:30:43

EXISTS 子句中的子查询实际上并未命中表、视图或其他。

Your subquery in the EXISTS clause isn't actually hitting a table, view or other.

丑丑阿 2024-10-23 06:30:43

您的子选择缺少 FROM 子句。

选择
个体_聚合.code

个体_聚合
在哪里
代码 = 'xx'
AND individual_aggregate.type = 'D'

问候
西格斯特德

Your sub-select is missing the FROM clause.

SELECT
individual_aggregate.code
FROM
individual_aggregate
WHERE
code = 'xx'
AND individual_aggregate.type = 'D'

Regards
Sigersted

东风软 2024-10-23 06:30:42

您是否想检查是否有人注册了某个社会安全号码?

如果是,我所做的是连接两个表
并返回等于特定社会安全号码的行。

您可以添加到 WHERE 语句(AND IA.code = 'XX' AND IA.Type = 'D')

SELECT SP.Name
FROM simple_person AS SP
INNER JOIN individual_aggregate AS IA ON SP.grid = IA.grid
WHERE SP.SSC = {someNumber}

对您有帮助吗?

did you wanted to check if there is a person that registered on a some Social security number?

if yes what i did is join between the two tables
and return the rows that equal to a specific social security number.

you can add to the WHERE statement (AND IA.code = 'XX' AND IA.Type = 'D')

SELECT SP.Name
FROM simple_person AS SP
INNER JOIN individual_aggregate AS IA ON SP.grid = IA.grid
WHERE SP.SSC = {someNumber}

helped you?

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