SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: Alias Question

  1. #1
    SitePoint Addict
    Join Date
    Aug 2009
    Posts
    299
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Alias Question

    Hi Chaps,

    Have a quick one for you...

    In a SQL Query, I know you can create an alias for column name, eg.

    Code:
    ...tbl_jobxml.job1 as job2
    but can you create an alias for the value within that column, eg.

    Code:
    ...tbl_jobxml.job1='y' as job2='Complete'
    Sorry if this is dumb question, but better to ask that claim ignorance!

    ????

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    select 'Complete' as job2

  3. #3
    SitePoint Addict
    Join Date
    Aug 2009
    Posts
    299
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry to the delay in responding, basically this is what I want to do:

    I want to show all results when:

    - tableA
    projectstatus='complete'

    - tableB
    projectstatus='complete'

    - tableC
    jobstatus='y'

    I'm familiar with UNIONs and INNER JOINs, it's just not sure how to go about getting all the results form the 3 tables, when the values are different.

  4. #4
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,508
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Code MySQL:
    SELECT
       ...
    FROM tableA
    INNER JOIN tableB
    ON ...
    INNER JOIN tableC
    ON ...
    WHERE tableA.projectstatus = 'complete'
    AND   tableB.projectstatus = 'complete'
    AND   tableC.jobstatus = 'y'

  5. #5
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,340
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    nice job, guido

    i was busy answering this same question on two other forums, so you beat me to it here on sitepoint

    samule, you can save yourself some effort by posting only here at sitepoint, we have all the best database guys right here

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


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
  •