对多个表运行查询
我正在尝试在两个表中进行查询:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
EXISTS
子句中的子查询实际上并未命中表、视图或其他。Your subquery in the
EXISTS
clause isn't actually hitting a table, view or other.您的子选择缺少 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
您是否想检查是否有人注册了某个社会安全号码?
如果是,我所做的是连接两个表
并返回等于特定社会安全号码的行。
您可以添加到 WHERE 语句(AND IA.code = 'XX' AND IA.Type = 'D')
对您有帮助吗?
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')
helped you?