FIND_IN_SET. A handy little MySQL function

MariaDB MySQL

At AtYourService.com.cy we send a lot of emails. Especially when you compare it to the Cyprus market we send even more. Advocates of the Lean method we measure and report EVERYTHING. We even monitor some data real time. Reporting of a live table is a no go when you are running a real time application. So a lot of reports contain a lot of GROUP_CONCAT fields. When it comes to combinig these reprots with a semi hot table its kind of a mess to join over a field containing comma separated keys from another table.

SELECT * FROM 
table1,report_table2 
WHERE 
date BETWEEN 2015-01-01 AND NOW() 
AND table1.id in (x1,x2,x3)

But x1,x2,x3 is actually a text field in report_table2.

WHERE id in (table.field)

throws an error (well maybe not if the values are integers and MySql CASTs them to the first scalar value and if you are lucky the expression will evaluate to true if you hit the first one)

The solution?

SELECT * FROM 
table1,report_table2 
WHERE 
date BETWEEN 2015-01-01 AND NOW() 
AND FIND_IN_SET(table1.id,report_table2.field)

Maybe I should have known this but I didnt. It blew my mind and I thought I had to share.

Share your favourite MySQL function in the comments below

My plan to teach my 3 year old daughter programming looks promising.

Lego parts used to teach my daughter programming

I have a 3 year old daughter. She is a challenge to raise but she always makes me proud. My time with her is very limited but since day zero I do my best in making our time together as positive as possible. I dont want to be the pressurising parent that obsesses about making a clone of theirs but I truly believe that problem solving skills can be developed from a very young age. So I did my research and came with a way to teach my daughter programming using lego bricks.

The target

Model core mathematical functions and basic algebra using lego bricks

Time period

2 years

Facts

3 year old daughter

Unlimited supply of simple lego bricks (child friendly)

Lego parts used to teach my daughter programming
Lego parts used to teach my daughter programming

The girl knows numeric representation up to 10 and she can count objects and identify basic colours and shapes.

How I started.

I sat down with her and build walls with the lego bricks. I use a variety of techniques and told her to throw them to see how the break. Eventually she could identify the strongest and would do it from scratch.

Last summer she started drawing (vaguely) shapes using pen and paper.

Today I told her to make a triangle using her legos. I left her alone and I observed from a distance. She was just making random shapes and I thought “ok maybe I m aiming too high here”

I eventually hear her shouting “triangle, triangle”. I maybe parent blind (Failing to observe the truth because I am a parent) but I am very proud of the result.

triangle using lago bricks made by a 3 year old girl
triangle using lego bricks made by a 3 year old girl

Notice the bottom layer. She made the triangle but it wouldn’t hold itself together. She could just call me at that stage but all those construction lessons paid off.

Next steps

Tomorrow I will give her two pixel bricks only and see how she handles that.

I will then follow with colour limitations and then introduce the notion of lengths of sides.

After going through all the shapes I believe we will have a substantial way of explaining a problem so that she can go ahead and try to solve it.

 

 

PHP – Object Oriented language or an HTMLTemplate engine?

I am working on a web application project at work for the past month! I am the middle man between the hardcore object oriented software developer who is treating php as java, and the fancy, mind joggling html5/ javascript / css expert! I was assigned to merge the work of these two. I can honestly say it is a mother fucker. Yes treating php as a purely object oriented language helps keep things tight and consistent! You could even argue that it is a portability issue! You can migrate your application to various platforms by keeping the logic separate from the presentation!

WHY WOULD ANYONE USE SUCH A VERSATILE LANGUAGE LIKE PHP AND CONFINE IT WITHIN THE WALLS OF A COMPILED LANGUAGE ENVIRONMENT?

Come on people! PHP was written to be an html template itself!  There is no need to go overboard with 1000 classes and functions. Use it in context with everything! We are living in the age of extreme programming. There is a huge variety of frameworks to which people put a lot of hard work and made the as robust as they get! Why waste time in reinventing the wheel when you can design the super car of your dreams!