Results 1 to 7 of 7

Thread: platform independent alternative to group_concate, MYSQL < 4

  1. #1
    Join Date
    Apr 2003
    Posts
    42
    Rep Power
    0

    Question platform independent alternative to group_concate, MYSQL < 4

    i am designing a car management module in php and most the servers hosting and especially the one i am one are still using MYSQL<4. Now the problem is that i have two tables:

    CAR, CARDETAILS #join by carid (auto on car)

    what i initially wanted to achieve would have been dealt with using the GROUP_CONCATE aggregate function, but this is not available on versions less than 4. Point being to build a string out of the car details, if you get what i mean

    I have seen alternatives but none boast platform independence, nor any that i have found support the LINUX box i am hosting on....

    does anyone have any other alternatives they can send my way
    MSI K7N2G - ILSR V1.2
    KINGSTON 512 MB DDR
    AMD Athlon XP 2200
    ATI RAEDEON 9000 pro 128MB DDR
    IBM 123GB 72000RPM
    PIONEER 4X DVDR
    LOGITECH 400W THX Certified

    ...::just let it fly::....

  2. #2
    Join Date
    Jul 2004
    Posts
    264
    Rep Power
    0

    Default Re: platform independent alternative to group_concate, MYSQL < 4

    i take it that from the design you have each detail for each car is in multiple rows in the cardetails table and you want to be able to concatenate all of the details for each car into one string ... correct me if i am wrong ....

    i see that you are going to have to depend a little more on the language you are using to interface the mysql DB than on the SQL....

    one solution i can think of right now is for you to just join the two tables and loop though the resultset concatenating the details of each car into a separate string variable .....

    here is a limited example in php i can think of right now:

    PHP Code:
    //Initialize $resultset
    //This is to be done after the resultset has been obtained from the Db
    while ($row mysql_fetch_array($resultset)){
        
    $details[$row['carid']] .= $row['details']; //where carid and details are actual columns in the resultset

    that code generates an associative array of concatenated details for each carid

    try this out and tell me if it helped your cause

  3. #3
    Join Date
    Apr 2003
    Posts
    42
    Rep Power
    0

    Default Re: platform independent alternative to group_concate, MYSQL < 4

    thanx aonekilla's , but I should have stated that i have consider options similar to that, my problem is trying to find the least memory intensive query to achieve this.

    I am striving to hit the dbase as little as possible, thats why i was hoping for an aggregate function which i could create in the version i will be using and have it working like the latest releases.

    Thanx though, hope someone else have another option...but the loop is hopefully my last restort
    MSI K7N2G - ILSR V1.2
    KINGSTON 512 MB DDR
    AMD Athlon XP 2200
    ATI RAEDEON 9000 pro 128MB DDR
    IBM 123GB 72000RPM
    PIONEER 4X DVDR
    LOGITECH 400W THX Certified

    ...::just let it fly::....

  4. #4
    Join Date
    Feb 2003
    Posts
    3,184
    Rep Power
    0

    Default Re: platform independent alternative to group_concate, MYSQL < 4

    build the string separately, when you do the update for the record insert string into a text field

  5. #5
    Join Date
    Jun 2002
    Posts
    648
    Rep Power
    0

    Default Re: platform independent alternative to group_concate, MYSQL < 4

    I totaly agree with Owen. You will get the best performance doing it that way (assuming that car details is viewed much more frequently that being updated). That's why I love databases (such as Postgresql) that uses triggers. Such a function could be done in an (update/insert) trigger.

    Remember though that each time you update both tables, you will have to update this text field in order to keep the info current.

  6. #6
    Join Date
    Apr 2003
    Posts
    42
    Rep Power
    0

    Thumbs up Re: platform independent alternative to group_concate, MYSQL < 4

    point taken and since i am out of time... i might just exercise that option.

    But i may just change it l8r.

    when it all boils down, i like the sql to do what it was made for

    thanx
    MSI K7N2G - ILSR V1.2
    KINGSTON 512 MB DDR
    AMD Athlon XP 2200
    ATI RAEDEON 9000 pro 128MB DDR
    IBM 123GB 72000RPM
    PIONEER 4X DVDR
    LOGITECH 400W THX Certified

    ...::just let it fly::....

  7. #7
    Join Date
    Feb 2003
    Posts
    3,184
    Rep Power
    0

    Default Re: platform independent alternative to group_concate, MYSQL < 4

    sometimes people like to get "evil" with the queries - really I've seen it happen

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •