SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist stonedeft's Avatar
    Join Date
    Aug 2009
    Posts
    586
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    mysql query join ids

    Hello forums

    I have this table

    id year make model product_id
    1 2001 Ford F-150 100
    2 2001 Ford F-150 101
    3 2001 Ford F-150 102


    I want to copy this to a view table with end result like this

    id year make model product_id
    1 2001 Ford F-150 100,101,102

    maybe something like:

    Code:
    CREATE OR REPLACE VIEW view_table AS
    SELECT * FROM table
    Is this even possible?

    Thanks
    Don't Panic

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,017
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    Code:
    SELECT MIN(id) AS id
         , `year`
         , make 
         , model 
         , GROUP_CONCAT(product_id) AS product_id
      FROM daTable
    GROUP
        BY `year`
         , make 
         , model
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Evangelist stonedeft's Avatar
    Join Date
    Aug 2009
    Posts
    586
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wow GROUP_CONCAT
    Thanks r937 I'll experiment on that...
    Don't Panic


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
  •