SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Zealot erikwebb's Avatar
    Join Date
    Dec 2003
    Location
    Atlanta, GA
    Posts
    150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [RESOLVED] Using a Field Multiple Times in One Statement?

    I am working on a ticketing system and need to pull the same field from a table twice. In my ticket table there is a field that links to the creator's contact ID as well as the assigned person's contact ID. Basically, both of these link to the ID field in the contact table. Doing this connection is not the problem. I need to pull out <contact table>.name twice, once for each ID (creator, assigned). MySQL is pulling only one of the names, and is simply displaying it twice. A sample of what I have so far is below:
    Code:
    SELECT B.name, B.name AS assignee 
       FROM ticket A, contacts B 
       LEFT JOIN B ON A.assigned_id=B.id 
       WHERE A.creator_id=B.id
    Last edited by erikwebb; Feb 3, 2006 at 14:32.

  2. #2
    reads the ********* Crier silver trophybronze trophy longneck's Avatar
    Join Date
    Feb 2004
    Location
    Tampa, FL (US)
    Posts
    9,854
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Code:
    SELECT a.name as assignee
         , c.name as creator
      FROM ticket t
      JOIN contacts a
        ON a.id = assigned_id
      JOIN contacts c
        ON c.id = creator_id

  3. #3
    SitePoint Zealot erikwebb's Avatar
    Join Date
    Dec 2003
    Location
    Atlanta, GA
    Posts
    150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a ton, joins always give me problems.


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
  •