本文介绍了内部联接的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好!

我有一个雇员表,其中有用于当前区地址和永久区地址的条目.我也有一个表master_district,其中有900个区.现在master_employee中每个雇员都有两个District条目.我的问题是如何使用内部联接来获取其ID存储在master_employee中的区.
有两个地区的条目,所以如果我使用

Hello!!

I have a employee table in which there are entries for present District address and for permanent district address. I also have a table master_district in which there are some 900 districts. now there are two entries of district for each employee in master_employee. my problem is that how to use inner join to get district whose id is stored in master_employee.
there are two entries for district so if i am using

Select me.name,me.name_H,me.nationality,me.cast,me.sex,me.permanent_address,ms.state_name,md.dist_name,me.present_address,ms.state_name,md.dist_name,me.father_husband_name,me.date_of_birth,me.personal_id_mark,me.Qualifications from master_employee me  inner join master_state ms on me.state_present_address=ms.state_id   inner join master_district md on me.dist_permanent_address=md.dist_id where me.unqid=54


然后,因为仅在1个条件下为区创建了连接,所以如果我使用
,它将为两个id显示相同的区地址


then because join is created only on 1 condition for district so it is showing same district address for both id''s how ever if i use

Select me.name,me.name_H,me.nationality,me.cast,me.sex,me.permanent_address,ms.state_name,md.dist_name,me.present_address,ms.state_name,md.dist_name,me.father_husband_name,me.date_of_birth,me.personal_id_mark,me.Qualifications from master_employee me  inner join master_state ms on me.state_present_address=ms.state_id  and me.state_permanent_address =ms.state_id inner join master_district md on me.dist_permanent_address=md.dist_id and me.dist_present_address=md.dist_id where me.unqid=12



则该命令没有显示任何数据.请告诉我如何根据区域ID使用内部联接为两个区域获取名称.



then there is no data shown for the command. Please tell me how to use inner join to get name for both the district according to there district id

推荐答案

Select me.name,
me.name_H,
me.nationality,
me.cast,
me.sex,
me.permanent_address,
(Select state_name from  master_state where state_id=me.state_permanent_address)
as PermanentState, 
(Select dist_name from  master_district where dist_id=me.dist_permanent_address) as PermanentDistrict,
me.present_address,
(Select state_name from  master_state where state_id=me.state_present_address)
as PresentState,
(Select dist_name from  master_district where dist_id=me.dist_present_address) as PresentDistrict,
me.father_husband_name,
me.date_of_birth,
me.personal_id_mark,
me.Qualifications 
from master_employee me  

where me.unqid=54



这篇关于内部联接的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-13 19:58