OUTER JOIN makes wrong record count

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
m227
Posts: 75
Joined: Mon 06 Aug 2007 12:41

OUTER JOIN makes wrong record count

Post by m227 » Thu 01 Jun 2017 15:24

Hi, i have query where I use OUTER JOIN to show also nonexistent records from other table. In design time it returns correctly 5 records. In runtime it returns only 4 (without one from outer join which is not existent in outer join query). What to do to get all 5 records?

Code: Select all

SELECT 
  OdczytM.ID,
  Uzytkownik_Nieruchomosc.Uzytkownik_numer,
  Uzytkownik_Nieruchomosc.Nieruchomosc_numer,
  CONCAT(Uzytkownik.login, " [", Oddzial.nazwa, "]") AS Uzytkownik,
  Oddzial.nazwa AS Oddzial,
  CONCAT(Nieruchomosc.nazwa, " [", Nieruchomosc.miejscowosc, "]") AS Nieruchomosc,
  DATE(Data) AS Dzien
FROM Uzytkownik_Nieruchomosc 
LEFT OUTER JOIN OdczytM ON (OdczytM.Nieruchomosc_numer = Uzytkownik_Nieruchomosc.Nieruchomosc_numer)
LEFT JOIN Uzytkownik ON Uzytkownik.numer               = Uzytkownik_Nieruchomosc.Uzytkownik_numer
LEFT JOIN Oddzial    ON Oddzial.numer                  = Uzytkownik.Oddzial_numer
LEFT JOIN Nieruchomosc ON Nieruchomosc.numer           = Uzytkownik_Nieruchomosc.Nieruchomosc_numer
WHERE 
  ((Uzytkownik_Nieruchomosc.Uzytkownik_numer = :uzytkownik) OR (IFNULL(:uzytkownik, 0) = 0))
AND ((DATE(Data) > :dataod) OR (:dataod IS NULL) )

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: OUTER JOIN makes wrong record count

Post by ViktorV » Fri 02 Jun 2017 09:25

Unfortunately, we could not reproduce the problem.
In order to get a detailed answer, please compose a small sample demonstrating the issue and send it to us using the contact form https://www.devart.com/company/contactform.html including scripts for creating and filling database objects. Also please specify the exact versions of the used MyDAC, MySQL server and IDE.

m227
Posts: 75
Joined: Mon 06 Aug 2007 12:41

Re: OUTER JOIN makes wrong record count

Post by m227 » Fri 02 Jun 2017 09:30

I am sorry, after another hour of investigation I found my fault. Please dismiss or delete this thread.

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: OUTER JOIN makes wrong record count

Post by ViktorV » Fri 02 Jun 2017 09:55

Glad to see that the issue was resolved.
Feel free to contact us if you have any further questions about our products.

Post Reply