想要使用nodejs中的join来获取同一用户的多个记录

时间:2017-12-10 02:49:19

标签: mysql node.js join

我有4个申请人表,即申请人教育,申请人专业信息,申请人项目,申请人证书。我想制作e功能,当我通过申请人的id时,在那个申请人的基础上我想从这4个表中获取该申请人的数据。我有3个相同申请人的项目。现在,当我查询数据库时,它将从所有4个表中返回完整数据集3次,因为在applicantProfessionalInfo表中,同一申请人有3个作业记录。在申请人的3个表的其余部分中,该用户有一条记录。这是我的加入查询

https://sqliteonline.com/#fiddle-5a2c8d159b451a3mjb0384tl

我从api response

收到这种格式的数据
{
"meta": {
    "status": 200,
    "message": "Success"
},
"data": [
    {
        "FirstName": "Saad",
        "LastName": "Subzwari",
        "FatherName": "Naeem Uz Zafar Subzwari",
        "Contact": "923485255",
        "Address": "b17/519",
        "Cnic": "42501-6143456-9",
        "ProfilePicture": "",
        "Gender": "Male",
        "DOB": "1992-05-07",
        "DegreeName": "BBA",
        "Major": "Accounting",
        "Institute": "Computer Colligiate",
        "CompletionDate": "2013-12-31T19:00:00.000Z",
        "Gpa": 2.9,
        "duration": "12 Months",
        "organization": "10 Pearls",
        "Position": "SQA",
        "CertificateName": ".Net Diploma",
        "Url": "www.afreekmoji.com",
        "Year": 2015,
        "ProjectTitle": "AfrikMoji",
        "Skills": "Bootstrap, Javascript",
        "ProjectDesc": "Emoji selling website"
    },
    {
        "FirstName": "Saad",
        "LastName": "Subzwari",
        "FatherName": "Naeem Uz Zafar Subzwari",
        "Contact": "923485255",
        "Address": "b17/519",
        "Cnic": "42501-6143456-9",
        "ProfilePicture": "",
        "Gender": "Male",
        "DOB": "1992-05-07",
        "DegreeName": "BBA",
        "Major": "Accounting",
        "Institute": "Computer Colligiate",
        "CompletionDate": "2013-12-31T19:00:00.000Z",
        "Gpa": 2.9,
        "duration": "5 Months ",
        "organization": "Axact",
        "Position": "Senior .Net Developer",
        "CertificateName": ".Net Diploma",
        "Url": "www.afreekmoji.com",
        "Year": 2015,
        "ProjectTitle": "AfrikMoji",
        "Skills": "Bootstrap, Javascript",
        "ProjectDesc": "Emoji selling website"
    },
    {
        "FirstName": "Saad",
        "LastName": "Subzwari",
        "FatherName": "Naeem Uz Zafar Subzwari",
        "Contact": "923485255",
        "Address": "b17/519",
        "Cnic": "42501-6143456-9",
        "ProfilePicture": "",
        "Gender": "Male",
        "DOB": "1992-05-07",
        "DegreeName": "BBA",
        "Major": "Accounting",
        "Institute": "Computer Colligiate",
        "CompletionDate": "2013-12-31T19:00:00.000Z",
        "Gpa": 2.9,
        "duration": "8 Months",
        "organization": "Tech Consultancy ",
        "Position": ".Net Developer",
        "CertificateName": ".Net Diploma",
        "Url": "www.afreekmoji.com",
        "Year": 2015,
        "ProjectTitle": "AfrikMoji",
        "Skills": "Bootstrap, Javascript",
        "ProjectDesc": "Emoji selling website"
    }
   ]
   }

在此数据中,数据重复3次,因为申请人在applicantProfessionalInfo表中有3个工作记录。但我希望有这样的数据

"data": [
    {
        "FirstName": "Saad",
        "LastName": "Subzwari",
        "FatherName": "Naeem Uz Zafar Subzwari",
        "Contact": "923485255",
        "Address": "b17/519",
        "Cnic": "42501-6143456-9",
        "ProfilePicture": "",
        "Gender": "Male",
        "DOB": "1992-05-07",
        "DegreeName": "BBA",
        "Major": "Accounting",
        "Institute": "Computer Colligiate",
        "CompletionDate": "2013-12-31T19:00:00.000Z",
        "Gpa": 2.9,
        "duration": "12 Months",
        "organization": "10 Pearls",
        "Position": "SQA",
        "duration": "5 Months ",
        "organization": "Axact",
        "Position": "Senior .Net Developer",
        "duration": "8 Months",
        "organization": "Tech Consultancy ",
        "Position": ".Net Developer"
    }

我怎样才能达到这个结果?

0 个答案:

没有答案