Querying related tables

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default Querying related tables

    Simple query question -

    I have a real estate table with various fields (Beds, Baths, SqFt, etc). One
    of the fields is BrokerID, which is foreign key linked to the primary key in
    the Broker table which holds names and contact info for each broker. I
    understand table relationships and what not. No problem there.

    Where I am lost is in the SQL query...here's an example.

    SELECT *
    FROM RealEstateTable
    WHERE RealEstateID = 1

    Let's say this query returns a record with a BrokerID of 3. How do I go about
    pulling the appropriate broker info from the Broker table?

    I know this is easy, but I'm not getting it.

    Thanks for everyone's time...Bill

    c1natra Guest

  2. Similar Questions and Discussions

    1. Querying one-to-many tables
      Hi, I have a database with, for the sake of simplicity, two tables with a one-to-many relationship. The first table is the user info and the...
    2. Querying data that matches in two different tables
      The code is attached. Basically there are two tables, contact and recruiter. When you initially add someone to contact, it also adds certain...
    3. Querying for unmatched records in two tables
      I have two tables - One contains a list of all the zip codes in the US. The other table is basically a mailing list containing addresses of people...
    4. querying a view of a lot tables
      I have setup a database to record our IP Account from ALL of our routers in a form. It's very slow and sometimes times out.. which is NO GOOD.. I...
    5. SHOW TABLES and related options for SQL are not working
      Hi, I have installed Perl from Active State.com in Win2K advanced server and no other Packages are installed. I am able to connect to Sql server...
  3. #2

    Default Re: Querying related tables

    select just the fields you want, not *
    from realestatetable r, brokertable b
    where t.brokerid = b.brokerid
    and maybe other constraints

    Originally posted by: c1natra
    Simple query question -

    I have a real estate table with various fields (Beds, Baths, SqFt, etc). One
    of the fields is BrokerID, which is foreign key linked to the primary key in
    the Broker table which holds names and contact info for each broker. I
    understand table relationships and what not. No problem there.

    Where I am lost is in the SQL query...here's an example.

    SELECT *
    FROM RealEstateTable
    WHERE RealEstateID = 1

    Let's say this query returns a record with a BrokerID of 3. How do I go about
    pulling the appropriate broker info from the Broker table?

    I know this is easy, but I'm not getting it.

    Thanks for everyone's time...Bill



    Dan Bracuk Guest

  4. #3

    Default Re: Querying related tables

    Thanks Dan -

    I'm assuming the "t" should be an "r"?

    select just the fields you want, not *
    from realestatetable r, brokertable b
    where r.brokerid = b.brokerid



    So then I simply call the broker information like this?

    <cfoutput query="queryname">#b.BrokerInfo#</cfoutput>

    Thanks for the quick reply...

    Bill

    c1natra Guest

  5. #4

    Default Re: Querying related tables

    No, you don't include the table prefix in the field output. If the field name
    in the table is BrokerInfo, that is what you put, even though you may have
    added the table prefix in the select statement.

    <cfoutput query="queryname">#BrokerInfo#</cfoutput>

    Phil

    paross1 Guest

  6. #5

    Default Re: Querying related tables

    Thanks guys, you've been a great help!

    Bill
    c1natra Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139