I actually saw this query being sent to a MySQL database that runs vBulletin:
SELECT * FROM style WHERE (styleid = 2 AND userselect = 1) OR styleid = 2 ORDER BY styleid ASC LIMIT 1;
While it’s possible that this query is generated through the php source code on the fly, this is a fail on so many levels:
- The selection of * is a bit of a no-no. Even in a table with only a few columns, do you really need all of them every time you run this query? My guess is no.
- The use of OR means that it doesn’t matter what the value of userselect is, so why bother checking it (much less checking it first)?
- You wouldn’t know this just by looking, but it turns out styleid is a primary key. Thus, the ORDER BY and LIMIT clauses are completely useless, as this query would only ever return (at most) one row.
Categories: Fail of the Day