Results 1 to 11 of 11
  1. #1
    Join Date
    Jan 2012
    Posts
    91

    Unanswered: How show in TDBGrid data from joining of two tables?

    In one table I have a foreign key which is appropriate to other key from another table. How to show value from another table? How to show the result of joining in DBGrid?

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    what is TDBGrid ?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Jan 2012
    Posts
    91
    Borland component in DBExpress technology.

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    oh, i see

    well, i should think you'd want to post your question in a more appropriate forum

    for example, https://forums.embarcadero.com/threa...68711&tstart=0
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  5. #5
    Join Date
    Jan 2012
    Posts
    91
    The answer there is almost impossible like miracle.

  6. #6
    Join Date
    Jan 2012
    Posts
    91
    I'll try to describe what I want to get. Example of a tables:

    TABLE_A
    ID NAME
    1 AA
    2 BB
    3 CC

    TABLE_B
    ID NAME
    1 1
    2 2
    3 3

    When I write query to show all records from table B, I can see in the column NAME only index ( 1,2,3 )
    "SELECT ID, NAME FROM TABLE_B"
    And I would do so: "SELECT ID, (INNER JOIN TABLE_A ON NAME=TABLE_A.ID) FROM TABLE_B"
    This query is obviously wrong. Is there something similar in SQL queries?
    I tried: "SELECT ID, NAME=(SELECT ID FROM TABLE_A) FROM TABLE_B"
    but I get reply: "Subquery returns more than 1 row" and I understand it as I want to main query to return all rows. How to join it?
    Last edited by duf; 06-24-12 at 17:40.

  7. #7
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Code:
    SELECT table_b.id
         , table_a.name
      FROM table_b
    INNER
      JOIN table_a
        ON table_a.id = table_b.name
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  8. #8
    Join Date
    Jan 2012
    Posts
    91
    Quote Originally Posted by r937 View Post
    Code:
    SELECT table_b.id
         , table_a.name
      FROM table_b
    INNER
      JOIN table_a
        ON table_a.id = table_b.name
    Thank You for reply.
    If you let me I ask one more question. If the result of this query is the empty set how to show the contents only of the table B in this query?

  9. #9
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by duf View Post
    If the result of this query is the empty set how to show the contents only of the table B in this query?
    change INNER JOIN to LEFT OUTER JOIN
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  10. #10
    Join Date
    Jan 2012
    Posts
    91
    Quote Originally Posted by r937 View Post
    change INNER JOIN to LEFT OUTER JOIN
    This effect I just expected! Excellent. Why does this query work that way? I do not know the expression OUTER. I knew only that it is the query LEFT JOIN. What is the difference between these queries? Thanks

  11. #11
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by duf View Post
    I do not know the expression OUTER.
    OUTER is an optional keyword but i always write it

    { LEFT | RIGHT } [OUTER] JOIN
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •