Board index » delphi » Multiple table query problem in Delphi

Multiple table query problem in Delphi

     I cannot display some fields from two separated tables in a DBGrid.
I have two tables: table1 contains "CustNo" and "Address", table 2 contains
"CustNo" and "DateOfBirth". I want to display them in a DBGrid as followed:
     CustNo        Address          DateOfBirth
      A            11 Iris St        03/06/90
      B            123 ....          10/03/76
      C            456 .....         04/05/70

    When I used heterogeneous query, It came out like this:
     CustNo        Address          DateOfBirth
   >  A            11 Iris St        03/06/90
      B            123 ....          03/06/90
      C            456 .....         03/06/90        
    Note that the DateOfBirth is the one at the cursor position. If I move
to B, the DateOfBirth will be all 10/03/76. In SQL, I wrote these lines:
   SELECT Table1.CustNo, Address, Table2.DateOfBirth
   FROM  ":Table1:Table1", ":Table2:Table2"
   WHERE CustNo = :CustNo

     If you know how to fix this problem, please let me know.
     Thanks in advance.

      Giao Nguyen

 

Re:Multiple table query problem in Delphi


You also need to add to your WHERE clause:
   AND Table1.CustNo = Table2.CustNo

In article <yangwu-3110961421590...@bcrkm84.ott.bnr.ca>, Yang Wu
<yan...@nortel.ca> writes

Quote
>     I cannot display some fields from two separated tables in a DBGrid.
>I have two tables: table1 contains "CustNo" and "Address", table 2 contains
>"CustNo" and "DateOfBirth". I want to display them in a DBGrid as followed:
>     CustNo        Address          DateOfBirth
>      A            11 Iris St        03/06/90
>      B            123 ....          10/03/76
>      C            456 .....         04/05/70

>    When I used heterogeneous query, It came out like this:
>     CustNo        Address          DateOfBirth
>   >  A            11 Iris St        03/06/90
>      B            123 ....          03/06/90
>      C            456 .....         03/06/90        
>    Note that the DateOfBirth is the one at the cursor position. If I move
>to B, the DateOfBirth will be all 10/03/76. In SQL, I wrote these lines:
>   SELECT Table1.CustNo, Address, Table2.DateOfBirth
>   FROM  ":Table1:Table1", ":Table2:Table2"
>   WHERE CustNo = :CustNo

>     If you know how to fix this problem, please let me know.
>     Thanks in advance.

>      Giao Nguyen

--
Alan Taylor

Other Threads