Article 1JKY4 CodeSOD: The Bare Minimum

CodeSOD: The Bare Minimum

by
Remy Porter
from The Daily WTF on (#1JKY4)

Let's say you needed to find the maximum and minimum values for a field in a SQL database. If you're like most people, you might write a query like SELECT MAX(someval), MIN(someval) FROM table.

That's the least you could do. That's the bare minimum. And do you want to be the kind of person who does the bare minimum? Kevin L's co-worker doesn't. He's a Brian.

 $querymin = " select hmid "; $querymin .= " from tagdetail "; $querymin .= " Where tagdetail.tag_ordr_ref=$grphdr_tag_ordr_ref"; $querymin .= " and tagdetail.refgrp=$grphdr_refgrp "; $querymin .= " order by hmid "; $resultmin = displayTable($conn_id1, $querymin, "N", ""); $counter = 1; foreach ($resultmin as $a) { $count_rcds = $count_rcds + 1; if ($counter == 1) { $min_hmid = (trim($a [hmid])); } $max_hmid = (trim($a [hmid])); $counter = $counter + 1; }

That's way better than using aggregate functions.

inedo50.png [Advertisement] Incrementally adopt DevOps best practices with BuildMaster, ProGet and Otter, creating a robust, secure, scalable, and reliable DevOps toolchain. TheDailyWtf?d=yIl2AUoC8zAaWDLiOZ8FVs
External Content
Source RSS or Atom Feed
Feed Location http://syndication.thedailywtf.com/TheDailyWtf
Feed Title The Daily WTF
Feed Link http://thedailywtf.com/
Reply 0 comments