我在mysql中有两个表
personal_details
reg_id fname lname mobile 1 x y 9999999999 2 m n 8888888888 3 a b 7777777777
education_details
edu_id reg_id qualification 1 1 High-school 2 1 Intermediate 3 2 High-school 4 2 Intermediate 5 2 B.A 6 3 High-school
结果,我想要的是
reg_id fname lname mobile qualification 1 x y 999999999 Intermediate 2 m n 888888888 B.A 3 a b 777777777 High-school
我已经尝试了很多但没有得到准确的结果
我到目前为止尝试过:
class PossibleAnswerSerializer(serializers.ModelSerializer):
companyId = serializers.SerializerMethodField()
def get_companyId(self, obj):
return obj.pollId.companyId
class Meta:
model = PossibleAnswer
fields = ('answerString', 'token', 'pollId', 'companyId',)
答案 0 :(得分:0)
使用join
select * from personal_details p
right join education_details e
on p.reg_id=e.reg_id
where edu_id=
(select max(edu_id) from education_details pnew where pnew.edu_id=p.edu_id)