SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: Select to include table.column with inner join?

  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 silver trophybronze trophy
    SitePoint Award Recipient r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    38,453
    Mentioned
    34 Post(s)
    Tagged
    1 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 silver trophybronze trophy
    SitePoint Award Recipient r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    38,453
    Mentioned
    34 Post(s)
    Tagged
    1 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
  •