---
title: "左连接查询出现重复"
author: "chamcon"
date: "2015-01-28T19:51:50Z"
tags: []
categories: ["开源软件"]
slug: "untitled"
draft: false
lastmod: "2015-01-28T19:51:50Z"
id: 2180976
url: "https://chamcon.iteye.com/blog/2180976"
---

使用左连接时，查出来的数据全部都一样的，其得到的值为笛卡尔积出现 n:n 的关系，如:left join pr\_stu\_elective pse on t.stu\_id=pse.fk\_stu\_id  出现该情况的原因是因为pse表中的fk\_stu\_id不能唯一标识pse表中的唯一记录，使得左表一条记录对应了多条pse表的记录，解决该情况即在左连接的on条件中加上能唯一表示pse表中的唯一记录