SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot jb007irl's Avatar
    Join Date
    Jun 2003
    Location
    Ireland
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Display value from another table

    Hello,

    I have a one-to-many relationship between a branches table and an employees table in a database. The branch_id field exists in the employees table.

    I am displaying the data from the employees table in a datagrid (employee_name, branch_id etc.) but I want to display the branch_name instead of the branch_id in the grid. The branches table exists in the database so I want to pull the branch_name from the branches table based on the branch_id that exists in the employees table.

    How can I pull the branch_name from the branch table when I locate the branch_id in the employees table?

    Thanks in advance.
    Is minic a bhris béal duine a shrón.

  2. #2
    SitePoint Wizard
    Join Date
    Jan 2005
    Location
    Denmark
    Posts
    1,222
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It depends:

    If you are using a datareader to directly get the data for the table i would simply suggest that you join the 2 tables in the datareader and include the branch_name in the select.

    If you are using a DataSet, first populating the dataset with the tables then I would suggest that you define a "calculated" column on the employee table. The expression would address the "parent" tables branch_name field.

    /mouse

  3. #3
    SitePoint Enthusiast
    Join Date
    Aug 2003
    Location
    va
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    You can use left outer join to get for the branch name.
    Here is an example:

    SELECT a.employee_name, b.branch_name
    FROM employees a LEFT OUTER JOIN branches b
    ON a.branch_id = b.branch_id
    http://www.GeekGig.com - Resources for the Geeks!


Bookmarks

Posting Permissions

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