SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Jan 2004
    Location
    Canada
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Select to include table.column with inner join?

    When joining two tables and they each have the same column name "id", the result will include data for both "id" columns in both tables.
    I would like the select statement to produce the list of columns with the table name prefixed:
    report.id, report.status, status.id, status.name

    Possible?

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,014
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    yes, possible, but not with the dots, rather, using column alias names

    example --
    Code:
    SELECT customers.id AS cust_id
         , orders.id AS order_id
      FROM customers
    INNER
      JOIN orders
        ON orders.customer_id = customers.id
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Member
    Join Date
    Jan 2004
    Location
    Canada
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What if I want this generically, meaning, I want to get all columns like that.
    Can I use the wild card '*'?

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,014
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by Gooofy View Post
    Can I use the wild card '*'?
    no, that wouldn't allow you to assign aliases, you have to write them all out
    r937.com | rudy.ca | 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
  •