I was just solving issue, where I needed to keep an order of items returned from the MySQL database listen in the WHERE IN clause.
SELECT * FROM table WHERE id IN (1,5,8,73,5,4,88)
This will return rows ordered by its primary key (in my case column id). Here is updated query, which will keep order of items listed in WHERE IN clause:
SELECT * FROM table WHERE id IN (1,5,8,73,5,4,88) ORDER BY FIELD(id,1,5,8,73,5,4,88)
Please note first item in brackets behind ORDER BY – there should be set same column, which was used at WHERE IN clause.
UPDATE: There was missing function called FIELD after ORDER BY – code is fixed now.
I was just asked to update tax classes on products in the catalogue. I found a easy and fast solution. Continue reading Magento: Changing Tax class on all products →
I needed to find out how to work with Google Geo API in my last project and especially with calculating a radius and distance between two geo points. Another goal was to get a latitude and longtitude from the address typed in the register form (in the background). Finally it was quiet easy. Here is the solution: Continue reading Google Maps API & PHP+MySQL – working with radius and distance →
I was looking for some nice freeware visual mysql database designer couple of weeks ago. I found two of them: DBDesigner 4 and MySQL Workbench. I must say, that both programs are really very similar, I mean from the view of the UI and menus structure. I gave a little user testing to both of them and designing database using these tools is very easy and fast… Continue reading MySQL visual database design →
Yesterday, I was solving simple database Query, where I needed to get some specific data. And while browsing thru MySQL documentation I found a very nice GROUP BY modifier which allows me make less queries and save some CPU on server. Let me explain how it works… Continue reading MySQL WITH ROLLUP modifier →