Records = Cursor.execute("SELECT cust_addr1, cust_addr2, cust_postcode, cust_telno_home, cust_email \
FROM tblcustomer, tblpet \
WHERE cust_surname = ? and tblpet.pet_deceased = ?" ,(SearchCriteria[0], "Y")).fetchall()
tblpet를 완벽하게 제거하면이 쿼리를 실행할 수 있지만 tblpet를 추가하면 쿼리가 실행되지만 결과가 복제됩니다. 그래서 5 개의 결과 대신 6300과 같은 것을 가졌지 만 모든 동일한 결과가 반복되었습니다.Pyodbc SQL SELECT Cursor.execute 중복 결과
감사
편집
지금 조인에 대해 말해위한 Mureinik 및 Siyual에에게 감사를 해결했습니다. 나는 이들
https://msdn.microsoft.com/en-us/library/bb243855(v=office.12).aspx
JOINing mdb tables with pyodbc
그것은 50 % 일 BU 그럼 내가 액세스에 가서 만들기 쿼리를 다음 SQL보기로 전환하고 복사 좋은 생각을 가지고 있었다 발견했다. 그것은 잘 작동하고 난 당신이 여기처럼 암시 가입 쓸 때
답변
Records = Cursor.execute("""SELECT tblcustomer.cust_addr1, tblcustomer.cust_addr2,
tblcustomer.cust_postcode, tblcustomer.cust_telno_home, tblcustomer.cust_email
FROM tblcustomer INNER JOIN tblpet ON (tblcustomer.cust_no = tblpet.pet_cust_no)
WHERE cust_surname = ? and tblpet.pet_deceased = ?""", (SearchCriteria[0],"Y")).fetchall()
: 당신은 명시 적
join
구문을 사용할 수 있습니다, 더 나은 아직또는를 JOIN'. 테이블을'JOIN'하려는 경우 명시 적'JOIN' 구문을 사용하십시오. (FROM 절에 쉼표를 사용하지 마십시오 - [심각하게는 1992 년에 사용되지 않았습니다] (http : //www.contrib.andrew. cmu.edu/~shadow/sql/sql1992.txt)) 'ON' 절에서 테이블이 어떻게 관련되어 있는지 보여줍니다. – Siyual
감사합니다. 질문이 업데이트되었습니다. –