在 SQLite iPhone 中加入查询 [英] Join query in SQLite iPhone

查看:43
本文介绍了在 SQLite iPhone 中加入查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个表 VisitsLabs
访问具有以下字段:id,patientID
实验室有这些字段:idVisitID
And Visit.id = Labs.VisitID

I have two tables Visits and Labs
Visit has these fields: id,patientID
Labs has these fields: id, VisitID
And Visit.id = Labs.VisitID

我想获取一位患者的所有旧实验室报告.但是在实验室表中我没有 patientID 字段,因此,我需要使用 visitID 字段,使用它我可以连接到访问表,然后我有 patientID

I want to get all old lab reports of a patient. But in lab table I don't have patientID field, so for that I need to make use of visitID field, using which I can connect to Visit table and there I have patientID

所以现在使用 visitID(一个常见字段)我想找出一个病人的所有旧实验室报告

So now using visitID(a common field) I want to find out all old lab reports of a patient

现在我想得到一个病人的所有实验室(我知道patientID)

Now I want to get all labs of a patient (I know patientID)

有人可以建议我加入查询吗?

Can anyone suggest me join query for this?

推荐答案

这是一个简单的INNER JOIN,对吧?

It's a simple INNER JOIN, right?

SELECT labs.* FROM labs INNER JOIN visit ON visit.id = labs.visitID AND patientID = ?

或者你可以做一个子选择:

Or you can do a subselect:

SELECT labs.* FROM labs WHERE visitID IN (SELECT visit.id FROM visit WHERE patientID = ?)

这篇关于在 SQLite iPhone 中加入查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆