Question about not required fields

Question about not required fields

Post by Norma » Wed, 31 Aug 2005 09:46:46



Hello,
I'm using Delphi5/ADO and Access2000.
In my app there are 2 very simple tables T1 and T2.
T1 has a field F joined to a field F in T2.
Field T1.F is defined as "not required" in Access, so that the user can leave it blank.
But I have a problem here: all records with blank T1.F1 disappear from DBGrid after they are posted.

I think the problem is related to SQL command I'm using:

SELECT T1.*, T2.* FROM T1, T2
WHERE T1.F = T2.F
ORDER BY T1.F

Since T2.F is required, there's no NULL value in T2.F, so there's no NULL value to match blank T1.F fields.
Please, what changes in SQL command are needed to do T1.F appearing in DBgrid when its value is blank/NULL ?
(Note: Access shows the records with blank T1.F, allowing user edit, choose values from T2 or leave it blank. I think Delphi/ADO can do this way too).

Thank you
 
 
 

Question about not required fields

Post by Yanni » Wed, 31 Aug 2005 16:14:56


This SQL statement is the same with

SELECT T1.*, T2.* FROM T1
INNER JOIN T2 ON T1.F = T2.F
ORDER BY T1.F

What you need is something like

SELECT T1.*, T2.* FROM T1
LEFT JOIN T2 ON T1.F = T2.F
ORDER BY T1.F

The above statement will return all the rows
from T1 but not all the records from T2 will
be returned unless all the records on T2 are
linked to T1.

Regards
Yannis.