Re: Get the lowest value out of different fields

From: Date: Wed, 03 Sep 2003 20:20:46 +0000
Subject: Re: Get the lowest value out of different fields
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-161591@lists.php.net to get a copy of this message
From: "Frank Keessen" <fkeessen@planet.nl> > I hope you can help me with this: > > I have a tabel in my database like this > > TEST > > fieldname Value's > > testid 1 > testf1 3 > testf2 4 > testf3 0 > testf4 2 > testf5 0 > > (so this is one record!) Those are columns, right? Anytime you have columns named like that it means you have a horrible database design.You're going to be better of pulling this into PHP and finding the min() number. Here's one way to do it in SQL, but you see how complex it is with just three columns: select case when a>0 and b>0 and c>0 then least(a,b,c) when a>0 and b>0 then least(a,b) when a>0 and c>0 then least(a,c) when b>0 and c>0 then least(b,c) when a>0 then a when b>0 then b when c>0 then c end from test; ---John Holmes...

« previous php.general (#161591) next »