MySQL Subqueries and INNER JOINs 2009 Apr 3
Two advanced MySQL tips today:
- Never use a subquery inside a WHERE field IN(…) list
- How-to: Update values in a table from a calculation that uses the table’s own values, in a single query
Two advanced MySQL tips today:
ORDER BY FIELD and GROUP_CONCAT() 2008 Jun 12I love databases because I always feel there is a way for retrieving my data in any shape or form I desire. Trying to find the correct syntax can sometimes be frustrating, however. Here are two tricks that have helped me during those special times:
FIELD() function comes in handy.
The disadvantage is that this will slow down your query. For maximum performance, store the field as an ENUM with the values defined in the correct order.
Scenario: We have multiple values spread out across rows a table, but need to retrieve them together in a single field without performing multiple queries. I'm doing this for my archive page--I want to retrieve a list of topic tags for each article, but I want to do it with the same query that selects all my articles. GROUP_CONCAT() is the answer for string concatenation.
The "topic" column could then return values such as "php,mysql,css".