首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何组合2条sql语句

如何组合2条sql语句
EN

Stack Overflow用户
提问于 2014-07-17 13:51:13
回答 1查看 54关注 0票数 0

我正在尝试从他们拥有的旧数据库中检索客户的数据。我需要的数据是这两个sql语句的混合。在第二条语句中,我如何组合它们以从enrol_stud表和Stud_Haddress表中获取所有数据。

语句1-我希望在语句2中包含来自Enrol_Stud和Stud_Haddress的所有数据

代码语言:javascript
运行
复制
select enrol_stud.*, stud_haddress.*
from enrol_stud_forms 
inner join enrol_stud on enrol_stud_forms.student_id = enrol_stud.student_id

语句2我希望在下面的语句中包含上面两个表中的数据。

代码语言:javascript
运行
复制
SELECT contact.*, vsmc.*, concarer1.*, salcarer2.*,  contact.firstname ||' 
'||contact.surname as STUDENT, salcarer1.salutation as CARER1_TITLE, concarer1.firstname as CARER1_FIRSTNAME, concarer1.surname  as CARER1_SURNAME, concarer1.email_address as CARER1_EMAIL, salcarer2.salutation as CARER2_TITLE, concarer2.firstname as CARER2_FIRSTNAME, concarer2.surname as CARER2_SURNAME, concarer2.email_address as CARER2_EMAIL

FROM get_currently_enroled_students ('now') gces
INNER JOIN student on gces.student_id = student.student_id
INNER JOIN contact on student.contact_id=contact.contact_id
INNER JOIN view_Student_mail_carers vsmc on student.student_id=vsmc.student_id
INNER JOIN contact concarer1 on vsmc.carer1_contact_id=concarer1.contact_id
INNER JOIN contact concarer2 on vsmc.carer2_contact_id=concarer2.contact_id
INNER JOIN salutation salcarer1 on concarer1.salutation_id=salcarer1.salutation_id
INNER JOIN salutation salcarer2 on concarer2.salutation_id=salcarer2.salutation_id
ORDER BY contact.surname, contact.firstname

我知道它在连接中,但我不知道如何包含它们。

EN

回答 1

Stack Overflow用户

发布于 2014-07-17 13:58:17

您可以尝试如下所示,将每个post的第一个语句中的列也包括如下所示的连接

代码语言:javascript
运行
复制
SELECT contact.*, 
vsmc.*, 
enrol_stud.*, <- here
stud_haddress.*, <-here
concarer1.*, 
salcarer2.*,  
contact.firstname ||' '||contact.surname as STUDENT, 
salcarer1.salutation as CARER1_TITLE, 
concarer1.firstname as CARER1_FIRSTNAME, 
concarer1.surname  as CARER1_SURNAME, 
concarer1.email_address as CARER1_EMAIL, 
salcarer2.salutation as CARER2_TITLE, 
concarer2.firstname as CARER2_FIRSTNAME, 
concarer2.surname as CARER2_SURNAME, 
concarer2.email_address as CARER2_EMAIL

FROM get_currently_enroled_students ('now') gces
INNER JOIN enrol_stud_forms on gces.student_id = enrol_stud_forms.student_id <- here
INNER JOIN enrol_stud on enrol_stud.student_id = gces.student_id <- here
INNER JOIN student on gces.student_id = student.student_id
INNER JOIN contact on student.contact_id=contact.contact_id
INNER JOIN view_Student_mail_carers vsmc on student.student_id=vsmc.student_id
INNER JOIN contact concarer1 on vsmc.carer1_contact_id=concarer1.contact_id
INNER JOIN contact concarer2 on vsmc.carer2_contact_id=concarer2.contact_id
INNER JOIN salutation salcarer1 
on concarer1.salutation_id=salcarer1.salutation_id
INNER JOIN salutation salcarer2 
on concarer2.salutation_id=salcarer2.salutation_id
ORDER BY contact.surname, contact.firstname
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24795779

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档