This week I had a SELECT a little more complex to execute, that I needed to concatenate a string with a field value of the own table that I was selecting. I didn’t wanted to split my sentence in two on PHP, I was convinced that should have a way to do that without depending on PHP to pass a field value to a second query.

My first attempt was doing:

My result was always empty or syntax error… Then I decided to research and I founded the “concat” (http://dev.mysql.com/doc/refman/5.5/en/string-functions.html#function_concat)

With it, I was able to do the WHERE as follows:

Off course this example is only instructive, but what happened on real life was pretty close of what is written above… The concat solved my problem and I didn’t needed to split my SELECT on two queries just because I didn’t knew how to concatenate a string with a field of the own selection.

Another lesson learned!

Leave a Reply

Your email address will not be published. Required fields are marked *

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.