News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Jonathan Snook's Blog:
Quick Merge in MySQL
August 22, 2006 @ 15:38:08

Jonathan Snook has a quick tip for PHPers out there using MySQL and looking for an easy way to concatinate a lot of data in your queries.

This is just a quick tip. If you have a bunch of data that you need to concatenate, take a look at MySQL's GROUP_CONCAT function.

For example, way back when, I wrote about (and subsequently weighting those tags) to an application. It was a very simple approach with each record having a tags field. It was just a simple text field and I stored all the tags with spaces. However, to pull out a list of all tags being used in the system, I returned the tags field from all records, looped through each record, exploding the tags onto an array.

Using the group_concat() function already in MySQL, he was able to reduce looping through his data, splitting on the spaces down to a single line call in SQL telling it to concatinate spaces. He includes the code (just a few lines) to get the job done.

0 comments voice your opinion now!
quick merge sql group_concat simple quick merge sql group_concat simple


blog comments powered by Disqus

Similar Posts

Douglas Brown's Blog: Three Important Tips to Write PHP Code Defensively

CodePoets.co.uk: A Quickstart to using PEAR with PHP

OneNextraPixel.com: 13 Useful WordPress SQL Queries You Wish You Knew Earlier

Felix Geisendorfer's Blog: New fix for array junkies: Set::merge assembles yummy arrays

Jonathan Snook's Blog: Quick Merge in MySQL


Community Events





Don't see your event here?
Let us know!


opinion introduction version package community release tool composer interview framework library series symfony security update voicesoftheelephpant language podcast install laravel

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework